Upd:更改数据源链接方式

master
duLingLing 5 years ago
parent 68042fe852
commit 536c691a20

@ -5,12 +5,12 @@
<parent> <parent>
<groupId>au.com.royalpay.payment</groupId> <groupId>au.com.royalpay.payment</groupId>
<artifactId>payment-parent</artifactId> <artifactId>payment-parent</artifactId>
<version>1.0.9</version> <version>1.0.11</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId> <artifactId>manage</artifactId>
<version>1.1.2</version> <version>1.1.3</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -206,6 +206,13 @@
<artifactId>mybatis-spring-boot-starter</artifactId> <artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version> <version>1.3.2</version>
</dependency> </dependency>
<!-- HikariCP data Source-->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

@ -1,6 +1,6 @@
package au.com.royalpay.payment.manage.pos.datasource; package au.com.royalpay.payment.manage.pos.datasource;
import org.springframework.beans.factory.annotation.Value; import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -19,19 +19,17 @@ import java.util.Map;
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
public class DataSourceConfiguration { public class DataSourceConfiguration {
@Value("${app.datasource.type:'com.alibaba.druid.pool.DruidDataSource'}")
private Class<? extends DataSource> dataSourceType;
@Bean(name = "masterDataSource") @Bean(name = "masterDataSource")
@ConfigurationProperties(prefix = "app.datasource.master") @ConfigurationProperties(prefix = "app.datasource.master")
public DataSource masterDataSource() { public DataSource masterDataSource() {
return DataSourceBuilder.create().type(dataSourceType).build(); return DataSourceBuilder.create().type(HikariDataSource.class).build();
} }
@Bean(name = "slaveDataSource") @Bean(name = "slaveDataSource")
@ConfigurationProperties(prefix = "app.datasource.slave") @ConfigurationProperties(prefix = "app.datasource.slave")
public DataSource slaveDataSource() { public DataSource slaveDataSource() {
return DataSourceBuilder.create().type(dataSourceType).build(); return DataSourceBuilder.create().type(HikariDataSource.class).build();
} }

@ -13,7 +13,7 @@ public class ReadWriteSplitRoutingDataSource extends AbstractRoutingDataSource {
@Override @Override
public Object determineCurrentLookupKey() { public Object determineCurrentLookupKey() {
DbContextHolder.DbType dataSource = DbContextHolder.getDbType(); DbContextHolder.DbType dataSource = DbContextHolder.getDbType();
logger.error("------------------当前数据源:{}---------------------",dataSource); logger.info("------------------当前数据源:{}---------------------",dataSource);
return dataSource; return dataSource;
} }

Loading…
Cancel
Save