use of org.springframework.context.annotation.Primary in project springBoot-learn-demo by nbfujx.
the class DruidOneConfig method DataSourceTransactionManagerOne.
// 数据源事务管理器
@Primary
@Bean
public DataSourceTransactionManager DataSourceTransactionManagerOne() {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSourceOne());
return dataSourceTransactionManager;
}
use of org.springframework.context.annotation.Primary in project Spring-Family by Sierou-Java.
the class MasterDataSourceConfig method masterDataSource.
@Bean(name = "masterDataSource")
@Primary
@ConfigurationProperties(prefix = "master.datasource")
public DataSource masterDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(user);
// System.out.println(SecurityAES.decrypt(password, "123"));
// dataSource.setPassword(SecurityAES.decrypt(password, "123"));
dataSource.setPassword(password);
dataSource.setMaxActive(maxActive);
dataSource.setInitialSize(initialSize);
dataSource.setMinIdle(minIdle);
// dataSource.setConnectionProperties("master.datasource.password=" + password);
return dataSource;
}
use of org.springframework.context.annotation.Primary in project Spring-Family by Sierou-Java.
the class MasterDataSourceConfig method masterSqlSessionFactory.
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(masterDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MasterDataSourceConfig.MAPPER_LOCATION));
return sessionFactory.getObject();
}
use of org.springframework.context.annotation.Primary in project spring-boot-quick by vector4wang.
the class DataSourcePrimaryConfig method testDataSource.
@Bean(name = "primaryDataSource", initMethod = "init", destroyMethod = "close")
@Primary
public DataSource testDataSource() throws SQLException {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(druidConfigPrimaryProperties.getDriverClassName());
druidDataSource.setUrl(druidConfigPrimaryProperties.getUrl());
druidDataSource.setUsername(druidConfigPrimaryProperties.getUsername());
druidDataSource.setPassword(druidConfigPrimaryProperties.getPassword());
druidDataSource.setInitialSize(druidConfigPrimaryProperties.getMinIdle());
druidDataSource.setMinIdle(druidConfigPrimaryProperties.getMinIdle());
druidDataSource.setMaxActive(druidConfigPrimaryProperties.getMaxActive());
druidDataSource.setMaxWait(druidConfigPrimaryProperties.getMaxWait());
druidDataSource.setTimeBetweenEvictionRunsMillis(druidConfigPrimaryProperties.getTimeBetweenEvictionRunsMillis());
druidDataSource.setMinEvictableIdleTimeMillis(druidConfigPrimaryProperties.getMinEvictableIdleTimeMillis());
druidDataSource.setValidationQuery(druidConfigPrimaryProperties.getValidationQuery());
druidDataSource.setTestWhileIdle(druidConfigPrimaryProperties.getTestWhileIdle());
druidDataSource.setTestOnBorrow(druidConfigPrimaryProperties.getTestOnBorrow());
druidDataSource.setTestOnReturn(druidConfigPrimaryProperties.getTestOnReturn());
druidDataSource.setPoolPreparedStatements(druidConfigPrimaryProperties.getPoolPreparedStatements());
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(druidConfigPrimaryProperties.getMaxPoolPreparedStatementPerConnectionSize());
druidDataSource.setFilters(druidConfigPrimaryProperties.getFilters());
return druidDataSource;
}
use of org.springframework.context.annotation.Primary in project spring-boot-quick by vector4wang.
the class DataSourcePrimaryConfig method testSqlSessionFactory.
@Bean(name = "primarySqlSessionFactory")
@Primary
public SqlSessionFactory testSqlSessionFactory(@Qualifier("primaryDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/primary/*.xml"));
return bean.getObject();
}
Aggregations