|
|
@ -6,9 +6,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
|
|
|
|
|
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
@ -20,17 +19,17 @@ import java.util.Map;
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@EnableTransactionManagement
|
|
|
|
@EnableTransactionManagement
|
|
|
|
public class DataSourceConfiguration {
|
|
|
|
public class DataSourceConfiguration {
|
|
|
|
@Value("${spring.datasource.type}")
|
|
|
|
@Value("${app.datasource.type:'com.alibaba.druid.pool.DruidDataSource'}")
|
|
|
|
private Class<? extends DataSource> dataSourceType;
|
|
|
|
private Class<? extends DataSource> dataSourceType;
|
|
|
|
|
|
|
|
|
|
|
|
@Bean(name = "masterDataSource")
|
|
|
|
@Bean(name = "masterDataSource")
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.master")
|
|
|
|
@ConfigurationProperties(prefix = "app.datasource.master")
|
|
|
|
public DataSource masterDataSource() {
|
|
|
|
public DataSource masterDataSource() {
|
|
|
|
return DataSourceBuilder.create().type(dataSourceType).build();
|
|
|
|
return DataSourceBuilder.create().type(dataSourceType).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean(name = "slaveDataSource")
|
|
|
|
@Bean(name = "slaveDataSource")
|
|
|
|
@ConfigurationProperties(prefix = "spring.datasource.slave")
|
|
|
|
@ConfigurationProperties(prefix = "app.datasource.slave")
|
|
|
|
public DataSource slaveDataSource() {
|
|
|
|
public DataSource slaveDataSource() {
|
|
|
|
return DataSourceBuilder.create().type(dataSourceType).build();
|
|
|
|
return DataSourceBuilder.create().type(dataSourceType).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|