use of org.springframework.context.annotation.Primary in project perry by ca-cwds.
the class CMSConfiguration method tokenTransactionManager.
@Bean
@Primary
@Autowired
public PlatformTransactionManager tokenTransactionManager(DataSource dataSource) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory(dataSource).getObject());
return transactionManager;
}
use of org.springframework.context.annotation.Primary in project tesla by linking12.
the class DruidDBConfig method dataSource.
// 声明其为Bean实例
@Bean(initMethod = "init", destroyMethod = "close")
// 在同样的DataSource中,首先使用被标注的DataSource
@Primary
public DataSource dataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
// configuration
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);
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
datasource.setProxyFilters(getProxyFilters());
try {
datasource.setFilters(filters);
} catch (SQLException e) {
logger.error("druid configuration initialization filter", e);
}
datasource.setConnectionProperties(connectionProperties);
return datasource;
}
use of org.springframework.context.annotation.Primary in project tesla by linking12.
the class DruidDBConfig method dataSource.
// 声明其为Bean实例
@Bean(initMethod = "init", destroyMethod = "close")
// 在同样的DataSource中,首先使用被标注的DataSource
@Primary
public DataSource dataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
// configuration
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);
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
logger.error("druid configuration initialization filter", e);
}
datasource.setConnectionProperties(connectionProperties);
return datasource;
}
use of org.springframework.context.annotation.Primary in project hub-alert by blackducksoftware.
the class DataSourceConfig method jpaTransactionManager.
@Bean
@Primary
public JpaTransactionManager jpaTransactionManager(final DataSource dataSource) {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setDataSource(dataSource);
return transactionManager;
}
use of org.springframework.context.annotation.Primary in project leopard by tanhaichao.
the class LeopardPropertyPlaceholderConfigurer method getBean.
public <T> T getBean(BeanFactory beanFactory, Class<T> requiredType) throws BeansException {
DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory;
Map<String, T> matchingBeans = factory.getBeansOfType(requiredType);
if (matchingBeans.isEmpty()) {
throw new NoSuchBeanDefinitionException(requiredType);
}
if (matchingBeans.size() == 1) {
return matchingBeans.entrySet().iterator().next().getValue();
}
for (Entry<String, T> entry : matchingBeans.entrySet()) {
T bean = entry.getValue();
// TODO 还没有支持Bean有AOP
Primary primary = bean.getClass().getDeclaredAnnotation(Primary.class);
if (primary != null) {
return bean;
}
}
throw new NoUniqueBeanDefinitionException(requiredType, matchingBeans.keySet());
}
Aggregations