我无法重现错误,但是请允许我更正您的属性文件,这样,如果 ,Spring实际上可以读取您的属性。
正如我在帖子中发现的一样的错误,为了解决该问题,您正在尝试增加datasource.max-active属性和其他属性,对吗?
因此,如果属性不在此默认应用程序属性中,则必须将它们编写为
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
最后但并非最不重要的一点是,您必须确保 您的max-idle属性。这就是为什么我添加了两个最后的日志记录和调试属性。
如果您仔细查看日志文件,请检查将其设置为哪些值。这是那条线对我的外观
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已经定了。
如果您想查看我在哪个简单的Spring-Data-REST应用程序中尝试了derby并遵循了以下属性,请检查此GitHub项目:derby-tomcat-database-error分支
可能有帮助,可能没有帮助,如果我写错了,请告诉我,我将删除帖子。
解决方法运行一段时间后,出现此错误。路径为[]的Servlet [dispatcherServlet]的Servlet.service()抛出异常[请求处理失败;嵌套的异常是org.springframework.orm.jpa.JpaSystemException:无法获取JDBC连接。嵌套的异常是org.hibernate.exception.GenericJDBCException:无法获取JDBCConnection,其根本原因是org.apache.tomcat.jdbc.pool.PoolExhaustedException:[http-nio-8081-exec-5]超时:池为空。30秒内无法获取连接,无可用[size:100; 繁忙:100;空闲:0;lastwait:30000]。
这是application.properties文件:
spring.datasource.url=jdbc:derby:/spring-boot/db;create=truespring.datasource.username=adminspring.datasource.password=1234spring.datasource.driver=org.apache.derby.jdbc.EmbeddedDriverhibernate.dialect = org.hibernate.dialect.DerbyDialectspring.jpa.generate-ddl=truespring.jpa.hibernate.ddl-auto = updatespring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContextspring.datasource.max-active=100spring.datasource.max-idle=8spring.datasource.min-idle=8