Browse Source

新增:查询兰图视图的jdbcTemplate

dev
wangxianzhang 3 years ago
parent
commit
88cf31cb0e
  1. 4
      epmet-user/epmet-user-server/pom.xml
  2. 64
      epmet-user/epmet-user-server/src/main/java/com/epmet/jdbc/config/JdbcDataSourceConfig.java
  3. 30
      epmet-user/epmet-user-server/src/main/java/com/epmet/jdbc/config/JdbcTemplateConfig.java
  4. 16
      epmet-user/epmet-user-server/src/main/resources/bootstrap.yml

4
epmet-user/epmet-user-server/pom.xml

@ -28,11 +28,11 @@
<artifactId>epmet-commons-mybatis</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<!--<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-dynamic-datasource</artifactId>
<version>2.0.0</version>
</dependency>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>

64
epmet-user/epmet-user-server/src/main/java/com/epmet/jdbc/config/JdbcDataSourceConfig.java

@ -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;
}
}

30
epmet-user/epmet-user-server/src/main/java/com/epmet/jdbc/config/JdbcTemplateConfig.java

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

16
epmet-user/epmet-user-server/src/main/resources/bootstrap.yml

@ -52,6 +52,22 @@ spring:
wall:
config:
multi-statement-allow: true
# 对接兰图数据源
yantai:
lantu:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/epmet_gov_voice?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
# 数据迁移工具flyway
flyway:
enabled: @spring.flyway.enabled@

Loading…
Cancel
Save