use of org.springframework.context.annotation.Primary in project tutorials by eugenp.
the class SessionConfig method connectionFactory.
@Bean
@Primary
public JedisConnectionFactory connectionFactory() {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName(properties.getProperty("spring.redis.host", "localhost"));
factory.setPort(properties.getProperty("spring.redis.port", Integer.TYPE, 6379));
factory.afterPropertiesSet();
factory.setUsePool(true);
return factory;
}
use of org.springframework.context.annotation.Primary in project flybiner-sso by youyouxi.
the class DruidConfig method druidDataSource.
/**
* @deprecated @Bean(destroyMethod = "close", initMethod = "init")
* 解决 druid 页面出错 (*) property for user to setup
*/
@Bean(destroyMethod = "close", initMethod = "init")
@Primary
public DataSource druidDataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
logger.error("druid configuration initialization filter", e);
}
return datasource;
}
use of org.springframework.context.annotation.Primary in project neweagle-api by apgzs.
the class DruidConfiguration method dataSource.
@Bean
@Primary
public DataSource dataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
// configuration
if (initialSize != null) {
datasource.setInitialSize(initialSize);
}
if (minIdle != null) {
datasource.setMinIdle(minIdle);
}
if (maxActive != null) {
datasource.setMaxActive(maxActive);
}
if (maxWait != null) {
datasource.setMaxWait(maxWait);
}
if (timeBetweenEvictionRunsMillis != null) {
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
}
if (minEvictableIdleTimeMillis != null) {
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
}
if (validationQuery != null) {
datasource.setValidationQuery(validationQuery);
}
if (testWhileIdle != null) {
datasource.setTestWhileIdle(testWhileIdle);
}
if (testOnBorrow != null) {
datasource.setTestOnBorrow(testOnBorrow);
}
if (testOnReturn != null) {
datasource.setTestOnReturn(testOnReturn);
}
if (poolPreparedStatements != null) {
datasource.setPoolPreparedStatements(poolPreparedStatements);
}
if (maxPoolPreparedStatementPerConnectionSize != null) {
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
}
if (connectionProperties != null) {
datasource.setConnectionProperties(connectionProperties);
}
List<Filter> filters = new ArrayList<>();
filters.add(statFilter());
filters.add(wallFilter());
datasource.setProxyFilters(filters);
return datasource;
}
use of org.springframework.context.annotation.Primary in project tutorials-java by Artister.
the class MasterDataSourceConfig method masterDataSource.
@Bean(name = "masterDataSource")
@Primary
public DataSource masterDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(user);
dataSource.setPassword(password);
return dataSource;
}
use of org.springframework.context.annotation.Primary in project lzl_workspace by hpulzl.
the class MasterDataSourceConfig method masterSqlSessionFactory.
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory() {
final SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
sessionFactoryBean.setDataSource(masterDruidDataSource());
try {
sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MASTER_MAPPER_LOCAL));
return sessionFactoryBean.getObject();
} catch (Exception e) {
logger.error("配置主库的SqlSessionFactory失败,error:{}", e.getMessage());
throw new RuntimeException(e.getMessage());
}
}
Aggregations