<bean id="dataSource_soccer_bet"
class="org.apache.commons.dbcp.BasicDataSource" singleton="true" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/hoop_soccer_bet?autoReconnect=true&useUnicode=true&characterEncoding=
max-idle: 10max-lifetime: 10000
min-idle: 5
initial-size: 5
test-on-borrow: false
test-while-idle: true
time-between-eviction-runs-millis: 18800
jdbc-interceptors: ConnectionStateSlowQueryReport(threshold=5)
validation-query: SELECT 1 FROM DUAL
方案1:application.properties里面添加即可
spring.datasource.druid.break-after-acquire-failure=true
spring.datasource.druid.connection-error-retry-attempts=1
1
2
1
2
方案2:动态数据源解决方案
DruidDataSource druidDataSource=new DruidDataSource()
druidDataSource.setUrl(dbInfo.getUrl())
druidDataSource.setUsername(dbInfo.getUserName())
druidDataSource.setPassword(dbInfo.getPassword())
druidDataSource.setConnectionErrorRetryAttempts(1) //失败后重连次数
druidDataSource.setBreakAfterAcquireFailure(true)
1
2
3
4
5
6
1
2
3
4
5
6
完成了,只会试一次,不成功不会无限尝试
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)