forked from rongchao/epmet-cloud-rizhao
4 changed files with 112 additions and 2 deletions
@ -0,0 +1,64 @@ |
|||
package com.epmet.jdbc.config; |
|||
|
|||
import com.alibaba.druid.pool.DruidDataSource; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
/** |
|||
* jdbc连接外部数据源配置 |
|||
*/ |
|||
@Configuration |
|||
public class JdbcDataSourceConfig { |
|||
|
|||
// ----------------对接兰图的数据源-------------------
|
|||
@Value("${spring.datasource.yantai.lantu.driver-class-name}") |
|||
private String yantaiLantuDriverClassName; |
|||
@Value("${spring.datasource.yantai.lantu.url}") |
|||
private String yantaiLantuUrl; |
|||
@Value("${spring.datasource.yantai.lantu.username}") |
|||
private String yantaiLantuUsername; |
|||
@Value("${spring.datasource.yantai.lantu.password}") |
|||
private String yantaiLantuPassword; |
|||
|
|||
@Value("${spring.datasource.yantai.lantu.initial-size}") |
|||
private Integer yantaiLantuInitialSize; |
|||
@Value("${spring.datasource.yantai.lantu.max-active}") |
|||
private Integer yantaiLantuMacActive; |
|||
@Value("${spring.datasource.yantai.lantu.min-idle}") |
|||
private Integer yantaiLantuMinIdle; |
|||
@Value("${spring.datasource.yantai.lantu.max-wait}") |
|||
private Long yantaiLantuMaxWait; |
|||
@Value("${spring.datasource.yantai.lantu.pool-prepared-statements}") |
|||
private Boolean yantaiLantuPreparedStatements; |
|||
@Value("${spring.datasource.yantai.lantu.max-pool-prepared-statement-per-connection-size}") |
|||
private Integer yantaiLantuPspcs; |
|||
@Value("${spring.datasource.yantai.lantu.time-between-eviction-runs-millis}") |
|||
private Long yantaiLantuTberm; |
|||
@Value("${spring.datasource.yantai.lantu.min-evictable-idle-time-millis}") |
|||
private Long yantaiLantuMeitm; |
|||
|
|||
// ----------------对接兰图的数据源-------------------
|
|||
|
|||
/** |
|||
* 烟台-连接兰图的数据源 |
|||
* @return |
|||
*/ |
|||
DataSource createYantaiLantuDataSource() { |
|||
DruidDataSource druidDataSource = new DruidDataSource(); |
|||
druidDataSource.setDriverClassName(yantaiLantuDriverClassName); |
|||
druidDataSource.setUrl(yantaiLantuUrl); |
|||
druidDataSource.setUsername(yantaiLantuUsername); |
|||
druidDataSource.setPassword(yantaiLantuPassword); |
|||
druidDataSource.setInitialSize(yantaiLantuInitialSize); |
|||
druidDataSource.setMaxActive(yantaiLantuMacActive); |
|||
druidDataSource.setMinIdle(yantaiLantuMinIdle); |
|||
druidDataSource.setMaxWait(yantaiLantuMaxWait); |
|||
druidDataSource.setPoolPreparedStatements(yantaiLantuPreparedStatements); |
|||
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(yantaiLantuPspcs); |
|||
druidDataSource.setTimeBetweenEvictionRunsMillis(yantaiLantuTberm); |
|||
druidDataSource.setMinEvictableIdleTimeMillis(yantaiLantuMeitm); |
|||
return druidDataSource; |
|||
} |
|||
} |
@ -0,0 +1,30 @@ |
|||
package com.epmet.jdbc.config; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Qualifier; |
|||
import org.springframework.boot.autoconfigure.AutoConfigurationPackage; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.jdbc.core.JdbcTemplate; |
|||
|
|||
import javax.sql.DataSource; |
|||
|
|||
/** |
|||
* jdbcTemplate配置类 |
|||
*/ |
|||
@Configuration |
|||
public class JdbcTemplateConfig { |
|||
|
|||
@Autowired |
|||
private JdbcDataSourceConfig jdbcDataSourceConfig; |
|||
|
|||
/** |
|||
* 烟台-兰图-jdbcTempalte对象 |
|||
* @return |
|||
*/ |
|||
@Bean |
|||
JdbcTemplate yantaiLantuJdbcTemplate() { |
|||
DataSource yantaiLantuDataSource = jdbcDataSourceConfig.createYantaiLantuDataSource(); |
|||
return new JdbcTemplate(yantaiLantuDataSource); |
|||
} |
|||
} |
Loading…
Reference in new issue