mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
+7
@@ -30,6 +30,9 @@ public class DruidDataSourceBuilder {
|
||||
|
||||
/**
|
||||
* For build multiple DruidDataSource, detail see document.
|
||||
*
|
||||
* -------
|
||||
* The method is history, and now you can use 'new DruidDataSourceWrapper()' instead.
|
||||
*/
|
||||
public DruidDataSource build() {
|
||||
return new DruidDataSourceWrapper();
|
||||
@@ -40,7 +43,11 @@ public class DruidDataSourceBuilder {
|
||||
* <p>
|
||||
* 这是为了兼容 Spring Boot 1.X 中 .properties 内配置属性不能按照配置声明顺序进行绑定,进而导致配置出错(issue #1796 )而提供的方法。
|
||||
* 如果你不存在上述问题或者使用 .yml 进行配置则不必使用该方法,使用上面的{@link DruidDataSourceBuilder#build}即可,Spring Boot 2.0 修复了该问题,该方法届时也会停用。
|
||||
*
|
||||
* fixed, the method will be removed in future versions.
|
||||
* @see DruidDataSourceWrapper#setMaxEvictableIdleTimeMillis(long)
|
||||
*/
|
||||
@Deprecated
|
||||
public DruidDataSource build(Environment env, String prefix) {
|
||||
DruidDataSource druidDataSource = new DruidDataSourceWrapper();
|
||||
druidDataSource.setMinEvictableIdleTimeMillis(
|
||||
|
||||
+17
-3
@@ -50,10 +50,9 @@ class DruidDataSourceWrapper extends DruidDataSource implements InitializingBean
|
||||
if (super.getUrl() == null) {
|
||||
super.setUrl(basicProperties.determineUrl());
|
||||
}
|
||||
if(super.getDriverClassName() == null){
|
||||
if (super.getDriverClassName() == null) {
|
||||
super.setDriverClassName(basicProperties.getDriverClassName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -96,5 +95,20 @@ class DruidDataSourceWrapper extends DruidDataSource implements InitializingBean
|
||||
super.filters.add(wallFilter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ignore the 'maxEvictableIdleTimeMillis < minEvictableIdleTimeMillis' validate,
|
||||
* it will be validated again in {@link DruidDataSource#init()}.
|
||||
*
|
||||
* for fix issue #3084, #2763
|
||||
*
|
||||
* @since 1.1.14
|
||||
*/
|
||||
@Override
|
||||
public void setMaxEvictableIdleTimeMillis(long maxEvictableIdleTimeMillis) {
|
||||
try {
|
||||
super.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis);
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
super.maxEvictableIdleTimeMillis = maxEvictableIdleTimeMillis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-8
@@ -1,15 +1,14 @@
|
||||
package com.alibaba.druid.spring.boot.demo.configurer;
|
||||
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
@Profile("issue-1796")
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/*@Configuration
|
||||
@Profile("issue-1796")*/
|
||||
public class Issue1796Configurer {
|
||||
|
||||
@Bean
|
||||
|
||||
+2
@@ -15,6 +15,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author lihengming [89921218@qq.com]
|
||||
*
|
||||
* for issue #1796, #3084, #2763
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = DemoApplication.class)
|
||||
|
||||
@@ -5,8 +5,8 @@ spring.datasource.password=sa
|
||||
# driver-class-name 非必填可根据url推断
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
|
||||
spring.datasource.druid.min-evictable-idle-time-millis=100000
|
||||
spring.datasource.druid.max-evictable-idle-time-millis=200000
|
||||
spring.datasource.druid.min-evictable-idle-time-millis=100000
|
||||
|
||||
# JPA
|
||||
spring.jpa.show-sql= true
|
||||
|
||||
Reference in New Issue
Block a user