【问题标题】:Spring boot JDBCConnectionException in multiple data source connection多数据源连接中的Spring Boot JDBCConnectionException
【发布时间】:2018-06-13 23:21:03
【问题描述】:

当我们尝试使用spring boot多数据源连接时出现JDBCConnection异常,前一天连接正常,但第二天出现连接异常,需要重启tomcat才能正常工作,可以任何body帮助我们了解导致连接在一段时间后关闭的确切属性

spring.xy.datasource.url=jdbc:mysql://azurnae-db013.xxx.yy.net:3306/devdb
spring.xy.datasource.username=user
spring.xy.datasource.password=pass
spring.xy.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.xy.datasource.pool-size=100

Below is the excpetion

could not prepare statement; nested exception is org.hibernate.exception.JDBCConnectionException: could not prepare statement",

【问题讨论】:

    标签: mysql hibernate spring-boot jdbc


    【解决方案1】:

    这是我的 tomcat webapp 配置:

    <Resource name="jdbc/itsme" 
              auth="Container" 
              type="javax.sql.DataSource" 
              maxTotal="100" 
              initialSize="1"
              maxActive="85"
              maxIdle="15"
              minIdle="1"
              maxWait="10000" 
              maxAge="3600000"
              timeBetweenEvictionRunsMillis="60000"
              minEvictableIdleTimeMillis="60000"
              validationQuery="SELECT 1"
              validationInterval="30000"
              testOnBorrow="true"
              removeAbandoned="true"
              removeAbandonedTimeout="60"
              driverClassName="com.mysql.cj.jdbc.Driver"/>
    

    您需要的属性是 minIdle、validationQuery、validationInterval、testOnBorrow 配置这些属性后,您应该不会再遇到问题了

    【讨论】:

      猜你喜欢
      • 2015-06-11
      • 1970-01-01
      • 2019-09-24
      • 2020-02-11
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多