SpringBoot发现最新版Druid重大问题(坑)

发现Druid问题

最近做项目,遇到大量插入的地方,经过大量的调试,最终发现是Druid连接池的问题,(以前一个大项目就遇到过Druid的坑),果断换成c3p0之后,压力测试哗哗上去了。

下面是更换c3p0方法。

1.修改pom.xml

导入c3p0依赖:


  com.mchange
  c3p0
  0.9.5.5

2.修改application.yml

spring:
 application:
  name: nh-tst
 http:
  encoding:
   charset: UTF-8
   enabled: true
   force: true
 datasource:
  driver-class-name: oracle.jdbc.driver.OracleDriver
 jpa:
  hibernate:
   ddl-auto: none
  show-sql: true
c3p0:
 jdbcUrl: jdbc:oracle:thin:@xxxxx:1522/prodpdb1
 user: xxxxxx
 password: xxxxxx
 driverClass: oracle.jdbc.driver.OracleDriver
 minPoolSize: 3
 maxPoolSize: 30
 maxIdleTime: 1800000
 acquireIncrement: 120
 maxStatements: 100000
 initialPoolSize: 5
 idleConnectionTestPeriod: 60
 acquireRetryAttempts: 30
 acquireRetryDelay: 10000
 breakAfterAcquireFailure: false
 testConnectionOnCheckout: false

3.增加DataSourceConfiguration.java类

package com.nh.fk.tst.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
public class DataSourceConfiguration {
 // c3p0 连接池
 @Bean(name = "dataSource")
 @Qualifier(value = "dataSource")
 @Primary
 @ConfigurationProperties(prefix = "c3p0")
 public DataSource dataSource() {
 return DataSourceBuilder.create().type(ComboPooledDataSource.class).build();
 }
}

打包,执行:世界又恢复了和平!!

到此这篇关于SpringBoot发现最新版Druid重大问题(坑)的文章就介绍到这了,更多相关SpringBoot Druid内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(SpringBoot发现最新版Druid重大问题(坑))