Spring Boot:Apache derby池为空. 30秒内无法获取连接 [英] Spring Boot: Apache derby pool empty. Unable to fetch a connection in 30 seconds

查看:978
本文介绍了Spring Boot:Apache derby池为空. 30秒内无法获取连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行一段时间后,出现此错误.
路径为[]的上下文中的servlet [dispatcherServlet]的 Servlet.service()引发异常[请求处理失败;嵌套的异常是org.springframework.orm.jpa.JpaSystemException:无法获取JDBC连接.嵌套的异常是org.hibernate.exception.GenericJDBCException:无法获取JDBC Connection,其根本原因是 org.apache.tomcat.jdbc.pool.PoolExhaustedException:[http-nio-8081-exec-5]超时:池为空. 30秒内无法获取连接,无可用[size:100;繁忙:100;空闲:0; lastwait:30000].

After some time of running I'm getting this error.
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection] with root cause org.apache.tomcat.jdbc.pool.PoolExhaustedException: [http-nio-8081-exec-5] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:100; busy:100; idle:0; lastwait:30000].

这是application.properties文件:

Here is the application.properties file:

spring.datasource.url=jdbc:derby:/spring-boot/db;create=true
spring.datasource.username=admin
spring.datasource.password=1234
spring.datasource.driver=org.apache.derby.jdbc.EmbeddedDriver
hibernate.dialect = org.hibernate.dialect.DerbyDialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext

spring.datasource.max-active=100
spring.datasource.max-idle=8
spring.datasource.min-idle=8

推荐答案

我无法重现错误,但请允许我更正您的属性文件,以便如果您使用的是SpringBoot 1.4或更高版本,Spring便可以读取您的属性. .

I cannot reproduce error, but let me correct your properties files, so that Spring actually can read your properties, if you are using SpringBoot 1.4 and higher.

正如我在发布具有相同错误的帖子中所发现的,以解决您遇到的问题正在尝试增加datasource.max-active和其他属性,对吗?

As I found in post with the same error, in order to solve the problem you are trying to increase datasource.max-active and other properties, right ?

因此,如果属性不在此默认应用程序属性,那么您必须将其编写为

So if properties are not in this default application properties, then you have to write them as

    spring.jpa.properties.*= # Additional native properties to set on the JPA provider.

因此,我建议您将application.properties文件更改为以下内容:

According to this I advice you to change application.properties file to the following:

    spring.datasource.url = jdbc:derby:/spring-boot/db;create=true
    spring.datasource.username = admin
    spring.datasource.password = 1234

    # this one is incorrect
    # spring.datasource.driver = org.apache.derby.jdbc.EmbeddedDriver
    # replace with the one below, otherwise Spring will use his own
    # derby driver
    spring.datasource.driver-class-name = org.apache.derby.jdbc.EmbeddedDriver

    # this one is incorrect as well
    # hibernate.dialect = org.hibernate.dialect.DerbyDialect
    # use the following way
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.DerbyDialect

    spring.jpa.generate-ddl = true
    spring.jpa.hibernate.ddl-auto = update
    spring.jpa.properties.hibernate.current_session_context_class = org.springframework.orm.hibernate4.SpringSessionContext

    # and in order for these guys to work you have to know
    # spring.datasource.max-active=100
    # spring.datasource.max-idle=8
    # spring.datasource.min-idle=8
    # your dbcp and look for documentation
    # below is the example for Tomcat
    spring.datasource.tomcat.max-active=100
    spring.datasource.tomcat.max-idle=8
    spring.datasource.tomcat.min-idle=8

    # make sure you check out the logging
    # this is IMPORTANT to see that your 
    # properties were ACTUALLY picked up
    logging.level.org.springframework.web = DEBUG
    logging.level.org.hibernate = DEBUG

前3个可以帮助您克服困难的属性最难解决.我从此处的帖子,最后的答案.它还链接到

The pre-last 3 properties that may help you overcome the difficulties are toughest to solve. I picked a knowledge from this post here, last answer. It has also link to Spring Boot 1.4.1.RELEASE documentation.

最后但并非最不重要的一点,您必须确保您的max-idle属性实际上是在Spring之前获得的.这就是为什么我加了两个 最后的日志记录和调试属性.

Last but not the least, you have to make sure that your max-idle properties were actually picked up by Spring. That is why I added two last logging and debugging properties.

如果您仔细查看日志文件,请检查将其设置为哪些值.这是那条线对我的样子

If you look carefully at your log file, please check to which values they were set. Here is how that line looks for me

    2016-11-17 11:40:27.875 DEBUG 32079 --- [           main] o.hibernate.internal.SessionFactoryImpl  : Instantiating session factory with properties: {java.vendor=Oracle Corporation, sun.java.launcher=SUN_STANDARD, catalina.base=/tmp/tomcat.736868414125414090.8080, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, catalina.useNaming=false, hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy, os.name=Linux, sun.boot.class.path=/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/resources.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/rt.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/sunrsasign.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/jsse.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/jce.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/charsets.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/jfr.jar:/usr/users/nikiforo/src/jdk1.8.0_73/jre/classes, hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext, java.vm.specification.vendor=Oracle Corporation, java.runtime.version=1.8.0_73-b02, user.name=nikiforo, javax.persistence.validation.mode=AUTO, user.language=en, sun.boot.library.path=/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/amd64, PID=32079, java.version=1.8.0_73, user.timezone=Europe/Berlin, sun.arch.data.model=64, java.endorsed.dirs=/usr/users/nikiforo/src/jdk1.8.0_73/jre/lib/endorsed, sun.cpu.isalist=, sun.jnu.encoding=UTF-8, file.encoding.pkg=sun.io, file.separator=/, java.specification.name=Java Platform API Specification, java.class.version=52.0, user.country=US, java.home=/usr/users/nikiforo/src/jdk1.8.0_73/jre, java.vm.info=mixed mode, os.version=4.1.20-11-default, hibernate.boot.CfgXmlAccessService.key=org.hibernate.boot.cfgxml.spi.LoadedConfig@6abb7b7d, hibernate.connection.datasource=org.apache.tomcat.jdbc.pool.DataSource@5c7dfc05{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.apache.derby.jdbc.EmbeddedDriver; maxActive=100

这是一条很长的线,但正如您所见,设置了max-active.

It is a long line, but as you see for me max-active was set.

如果您想查看我在哪个简单的Spring-Data-REST应用程序中尝试了derby以及以下属性,请检查

If you want to see in which simple Spring-Data-REST app I tried derby and following properties, check this mine GitHub project: derby-tomcat-database-error branch

可能有帮助,可能没有帮助,如果我错了,请告诉我,我将删除帖子.

It may help, may not, let me know if I'm wrong, I'll delete post.

这篇关于Spring Boot:Apache derby池为空. 30秒内无法获取连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆