Unable to acquire JDBC Connection;

导致原因

原因是mysql的设置的interactive_timeout和wait_timeout 两个值为8小时(28800s),所以此问题多数出现在隔夜再访问报错的情景,暴力的方式是修改msyql的配置文件,将这两个值设置为-1(-1表示永不超时)或者很大,但是此方法从开发的角度讲是不合理的,不能指望客户每套环境都要去改mysql的配置
 

 Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection

"Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection"
xml 格式

解决办法:dbcp的datasource添加如下两个属性即可
<property name="testOnBorrow" value="true"/>  
<property name="validationQuery" value="select 1"/>

application.yml根式

 dbcp2:
      test-on-borrow: true
      validation-query: "select 1"

猜你喜欢

转载自blog.csdn.net/yinlell/article/details/83855953