SpringJParepositoryFindall,Java8流,连接已被放弃

SpringJParepositoryFindall,Java8流,连接已被放弃,java,spring,database-connection,spring-data-jpa,java-stream,Java,Spring,Database Connection,Spring Data Jpa,Java Stream,我正在使用Spring Boot并尝试在mu存储库中执行findAll查询,该查询将返回一个结果流: public interface MyThingRepository extends JpaRepository<MyThing, String> { Stream<MyThing> findAll(); } public class MyScheduledJobRunner { @Autowired private MyThingReposito

我正在使用Spring Boot并尝试在mu存储库中执行findAll查询,该查询将返回一个结果流:

public interface MyThingRepository extends JpaRepository<MyThing, String> {
   Stream<MyThing> findAll();
}

public class MyScheduledJobRunner {

   @Autowired 
   private MyThingRepository myThingRepository;

   public void run() {
      try (Stream<MyThing> myThingsStream : myThingRepository.findAll()) {
        myThingsStream.forEach(myThing -> {
           // do some stuff
        });
        // myThingsStream.close(); // <- at one point even tried that, though the stream is wrapped in an auto-closing block. anyway, it did not help
       System.out.println("All my things processed.");
     }
     System.out.println("Exited the auto-closing block.");
   }
}
MyScheduledJobRunner:52是:

try (Stream<MyThing> myThingsStream : myThingRepository.findAll()) {

在池配置中,您只需添加:
“org.apache.tomcat.jdbc.pool.interceptor.resetAboutedTimer”

我确信它会返回列表和页面。我不确定它是否返回流。无论什么您是否编写了如下注释:@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME),@Service,您是否有数据源bean、存储库bean和服务bean的创建者(@Configuration)?是的。我所有的注释和bean都已设置。如果它们不被设置,那么我的数据库内容就不会工作,但它确实工作得很好。这就是我不喜欢在日志中出现的令人讨厌的废弃连接错误。这只是一个很小的例子。如果您查看我提供的文档链接,您将看到SpringBootJPA和Java8除了支持页面和集合外,还支持流。我之所以使用流而不是页面或集合,是因为这组神话可能非常庞大,我无法将其读入记忆。如果你试图获得一个列表,你能得到它吗?我通常不会这样做。我还声明了私有的最终myThingRepository,并创建了一个@Autowired构造函数。。我不是说这是原因,但不管怎样。是的,我会的。我也得到了那条小溪。问题不在于无法获取,而在于读取数据库条目后数据库连接未正确关闭。请详细说明该属性为什么以及如何帮助我?您可以在以下链接中找到信息:,,,此属性重置超时听起来不正常,为了使用开箱即用的Spring功能,我必须设置一些随机的Tomcat参数。在最好的情况下,在我看来,这是一个文档错误。无论如何,我无法让它工作(ClassNotFound)
try (Stream<MyThing> myThingsStream : myThingRepository.findAll()) {
spring:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost/mydb?useSSL=false
    username: user
    password: password
    initial-size: 10
    max-active: 100
    max-idle: 50
    min-idle: 10
    max-wait: 15000
    test-while-idle: true
    test-on-borrow: true
    validation-query: SELECT 1
    validation-query-timeout: 5
    validationInterval: 30000
    time-between-eviction-runs-millis: 30000
    min-evictable-idle-time-millis: 60000
    removeAbandonedTimeout: 60
    remove-abandoned: true
    log-abandoned: true