Spring Boot: Apache derby池为空。在30秒内无法获取连接。
Spring Boot: Apache derby池为空。在30秒内无法获取连接。
运行一段时间后,我遇到了这个错误。
在路径为[]的上下文中为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秒内无法获取连接,当前没有可用的连接[大小:100;繁忙:100;空闲:0;最后等待:30000]。
这是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
问题原因:应用无法从Apache Derby连接池中获取连接,导致在30秒内无法获取连接。
解决方法:根据问题中的提示,需要更改应用的配置文件来解决问题。具体的解决方法如下:
1. 打开应用的配置文件application.properties。
2. 修改以下属性的值:
- spring.datasource.url:设置Derby数据库的URL。
- spring.datasource.username:设置数据库的用户名。
- spring.datasource.password:设置数据库的密码。
- spring.datasource.driver-class-name:设置Derby的驱动类名。
- spring.jpa.properties.hibernate.dialect:设置Hibernate的方言。
- spring.jpa.generate-ddl:设置是否生成DDL语句。
- spring.jpa.hibernate.ddl-auto:设置Hibernate的DDL操作。
- spring.jpa.properties.hibernate.current_session_context_class:设置Hibernate的会话上下文类。
- spring.datasource.tomcat.max-active:设置连接池的最大活动连接数。
- spring.datasource.tomcat.max-idle:设置连接池的最大空闲连接数。
- spring.datasource.tomcat.min-idle:设置连接池的最小空闲连接数。
- logging.level.org.springframework.web:设置Spring的日志级别。
- logging.level.org.hibernate:设置Hibernate的日志级别。
3. 保存配置文件,并重新运行应用。
通过以上步骤,你可以解决(Spring Boot: Apache derby pool empty. Unable to fetch a connection in 30 seconds)这个问题。如果应用出现错误,你可以通过调整JDBC属性来解决连接池耗尽的错误。