springboot双数据源通过注解配置
1、在application.properties配置数据源的信息
#xxx oracle DB config
xxx.oracle.jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
xxx.oracle.jdbc.username=root
xxx.oracle.jdbc.password=root
xxx.oracle.druid.initialSize=5
xxx.oracle.druid.maxActive=10
#xxx pg DB config
xxx.pg.jdbc.driverClassName=org.postgresql.Driver
xxx.pg.jdbc.url=jdbc:postgresql://@127.0.0.1/xxx
xxx.pg.jdbc.username=root
xxx.pg.jdbc.password=root
xxx.pg.druid.initialSize=5
xxx.pg.druid.maxActive=10
2、oracle配置
@Component
@MapperScan(basePackages = "com.xxx.dao.oracle",sqlSessionFactoryRef = "oracleSqlSessionFactory")
public class DataSourceOracle {
private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceOracle.class);
private static final String driverClassName = "oracle.jdbc.driver.OracleDriver";
private static final String validationQuery = "SELECT 1 FROM DUAL";
private static final int maxWait = 60;
private static final boolean testOnBorrow = false;
private static final boolean testOnReturn = false;
private static final boolean testWhileIdle = true;
private static final int maxPoolPreparedStatementPerConnectionSize = 50;
private static final int timeBetweenEvictionRunsMillis = 60000;
p