2016-11-17 90 views
2

運行一段時間後出現此錯誤。
上下文中的servlet [dispatcherServlet]的Servlet.service()引發異常[請求處理失敗;嵌套異常是org.springframework.orm.jpa.JpaSystemException:無法獲取JDBC連接;嵌套異常是org.hibernate.exception.GenericJDBCException:無法獲取JDBC連接],其根本原因爲 org.apache.tomcat.jdbc.pool.PoolExhaustedException:[http-nio-8081-exec-5]超時:池空。無法在30秒內獲取連接,但沒有可用的[size:100;忙:100;空閒:0; lastwait:30000]。
Spring Boot:Apache derby池空。無法在30秒內獲取連接

這裏是application.properties文件:

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 
+0

通常由於糟糕的事務管理或自己搞亂連接。 –

回答

2

我無法重現錯誤,但讓我糾正你的屬性文件,使彈簧實際上可以讀取你的財產,如果您使用SpringBoot 1.4和更高的

正如我在post with the same error中發現的那樣,爲了解決這個問題,您試圖增加datasource.max-active等屬性,對不對?

所以,如果性能不是this default application properties,那麼你必須把它們寫爲

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

根據這個我建議你改變application.properties文件到以下幾點:

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個可能幫助你克服困難的屬性是最難解決的。我從this post here, last answer中挑選了一些知識。它也鏈接到Spring Boot 1.4.1.RELEASE documentation

最後但並非最不重要的一點,您必須確保您的max-idle屬性實際上是由Spring選取的。這就是爲什麼我添加了兩個 最後的日誌記錄和調試屬性。

如果仔細查看日誌文件,請檢查它們設置的值。下面是該行的樣子,我

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.Cfg[email protected]6abb7b7d, hiberna[email protected]5c7dfc05{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.apache.derby.jdbc.EmbeddedDriver; maxActive=100 

這是一個長線的,但你看我max-active設置。

如果你想在其中看到簡單的Spring-DATA-REST應用我想德比和以下屬性,檢查this mine GitHub project: derby-tomcat-database-error branch

它可以幫助,可能不會,讓我知道,如果我錯了,我會刪除帖子。

+0

我修改了我的application.properties,就像你說的,我再次嘗試。對於目前來說,問題似乎已經解決了。 \t感謝您的回答。我會多次嘗試此解決方案,如果我遇到錯誤,我會盡快與您聯繫。 @Alexander Nikiforov – mrtasln

+0

@mrt太好了!至少希望如果應用程序中斷,您可以通過調試選項看到更多輸出,並且還可以更改JDBC屬性來調整可能的池化耗盡錯誤,就像其他帖子中的人們所建議的一樣。 –

相關問題