1、配置application.yml文件
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:oracle:thin:@主机:端口号:ORCL
driverClassName: oracle.jdbc.driver.OracleDriver
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
maxOpenPreparedStatements: 20
validationQuery: SELECT 'x' FROM DUAL
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
useGlobalDataSourceStat: true
url: jdbc:oracle:thin:@主机:端口号:ORCL
driverClassName: oracle.jdbc.driver.OracleDriver
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
maxOpenPreparedStatements: 20
validationQuery: SELECT 'x' FROM DUAL
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
useGlobalDataSourceStat: true

2、配置DatasourceConfig类
public class DatasourceConfig {
@Bean(initMethod = "init", destroyMethod = "close")
@ConfigurationProperties(prefix = "spring.datasource.druid.slave")
public DataSource spcDataSource(DynamicDataSource dynamicDataSource) {
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
Map
targetDataSources.put(50,dataSource);
dynamicDataSource.setTargetDataSources(targetDataSources);
3、实现类上方配置注解
public class TestServiceImpl extends ServiceImpl implements TestService {
4、从库数据操作
public class TestServiceImpl extends ServiceImpl implements TestService {
private TestMapper mapper;
public List getStudentById(String id) {
if (StringUtils.isEmpty(id)) {
List list = this.mapper.getStudentById(id);
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
public void saveStudentEntity(StudentEntity studentEntity) {
this.save(StudentEntity);