Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -18,14 +18,6 @@ import java.sql.SQLException;
|
|||||||
//@Configuration
|
//@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DataBaseConfig {
|
public class DataBaseConfig {
|
||||||
@Value("${erp.oracle.enabled}")
|
|
||||||
private boolean oracleIsConnect;
|
|
||||||
@Value("${erp.oracle.jdbcurl}")
|
|
||||||
private String oracleJdbcUrl;
|
|
||||||
@Value("${erp.oracle.username}")
|
|
||||||
private String oracleUserName;
|
|
||||||
@Value("${erp.oracle.password}")
|
|
||||||
private String oraclePassword;
|
|
||||||
|
|
||||||
@Primary
|
@Primary
|
||||||
@Bean(name = "dataSource")
|
@Bean(name = "dataSource")
|
||||||
@@ -34,60 +26,4 @@ public class DataBaseConfig {
|
|||||||
return new DruidDataSource();
|
return new DruidDataSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = "dataSource1")
|
|
||||||
@ConditionalOnExpression("${erp.oracle.enabled:true}")
|
|
||||||
public DataSource dataSource1() {
|
|
||||||
System.out.println("是否连接oracle:"+oracleIsConnect);
|
|
||||||
System.out.println("erp.oracle.jdbcurl:"+oracleJdbcUrl);
|
|
||||||
System.out.println("erp.oracle.username:"+oracleUserName);
|
|
||||||
System.out.println("erp.oracle.password:"+oraclePassword);
|
|
||||||
log.info("是否连接oracle:"+oracleIsConnect);
|
|
||||||
log.info("erp.oracle.jdbcurl:"+oracleJdbcUrl);
|
|
||||||
log.info("erp.oracle.username:"+oracleUserName);
|
|
||||||
log.info("erp.oracle.password:"+oraclePassword);
|
|
||||||
|
|
||||||
String jdbcUrl = oracleJdbcUrl;
|
|
||||||
String userName = oracleUserName;
|
|
||||||
String password =oraclePassword;
|
|
||||||
|
|
||||||
DruidDataSource druidDataSource = new DruidDataSource();
|
|
||||||
String className;
|
|
||||||
try {
|
|
||||||
className = DriverManager.getDriver(jdbcUrl.trim()).getClass().getName();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new RuntimeException("Get class name error: =" + jdbcUrl);
|
|
||||||
}
|
|
||||||
if (StrUtil.isEmpty(className)) {
|
|
||||||
DataTypeEnum dataTypeEnum = DataTypeEnum.urlOf(jdbcUrl);
|
|
||||||
if (null == dataTypeEnum) {
|
|
||||||
throw new RuntimeException("Not supported data type: jdbcUrl=" + jdbcUrl);
|
|
||||||
}
|
|
||||||
druidDataSource.setDriverClassName(dataTypeEnum.getDriver());
|
|
||||||
} else {
|
|
||||||
druidDataSource.setDriverClassName(className);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
druidDataSource.setUrl(jdbcUrl);
|
|
||||||
druidDataSource.setUsername(userName);
|
|
||||||
druidDataSource.setPassword(password);
|
|
||||||
// 配置获取连接等待超时的时间
|
|
||||||
druidDataSource.setMaxWait(3000);
|
|
||||||
// 配置初始化大小、最小、最大
|
|
||||||
druidDataSource.setInitialSize(5);
|
|
||||||
druidDataSource.setMinIdle(5);
|
|
||||||
druidDataSource.setMaxActive(10);
|
|
||||||
|
|
||||||
// 如果链接出现异常则直接判定为失败而不是一直重试
|
|
||||||
druidDataSource.setBreakAfterAcquireFailure(true);
|
|
||||||
try {
|
|
||||||
druidDataSource.init();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Exception during pool initialization", e);
|
|
||||||
throw new RuntimeException(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return druidDataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user