SpringBoot发现最新版Druid重大问题

发现Druid问题

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

下面是更换c3p0方法。

1.修改pom.xml

导入c3p0依赖:

<dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5.5</version>
</dependency>

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();
	}
}

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

©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页