use of org.springframework.context.annotation.Primary in project kylo by Teradata.
the class LivyWranglerConfig method sparkConf.
/**
* Creates the Spark configuration.
*
* @return the Spark configuration
*/
@Bean
@Primary
public SparkConf sparkConf(final Environment env) /*, @Qualifier("sparkShellPort") final int serverPort*/
{
final SparkConf conf = new SparkConf().setAppName("SparkShellServer");
// .set("spark.ui.port", Integer.toString(serverPort + 1));
final Iterable<Map.Entry<String, Object>> properties = FluentIterable.from(Collections.singleton(env)).filter(AbstractEnvironment.class).transformAndConcat(new Function<AbstractEnvironment, Iterable<?>>() {
@Nullable
@Override
public Iterable<?> apply(@Nullable final AbstractEnvironment input) {
return (input != null) ? input.getPropertySources() : null;
}
}).filter(ResourcePropertySource.class).transform(new Function<ResourcePropertySource, Map<String, Object>>() {
@Nullable
@Override
public Map<String, Object> apply(@Nullable final ResourcePropertySource input) {
return (input != null) ? input.getSource() : null;
}
}).transformAndConcat(new Function<Map<String, Object>, Iterable<Map.Entry<String, Object>>>() {
@Nullable
@Override
public Iterable<Map.Entry<String, Object>> apply(@Nullable final Map<String, Object> input) {
return (input != null) ? input.entrySet() : null;
}
}).filter(new Predicate<Map.Entry<String, Object>>() {
@Override
public boolean apply(@Nullable final Map.Entry<String, Object> input) {
return (input != null && input.getKey().startsWith("spark."));
}
});
for (final Map.Entry<String, Object> entry : properties) {
conf.set(entry.getKey(), entry.getValue().toString());
}
return conf;
}
use of org.springframework.context.annotation.Primary in project leopard by tanhaichao.
the class LeopardPropertyPlaceholderConfigurer method getSingleBean.
public static <T> T getSingleBean(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());
}
use of org.springframework.context.annotation.Primary in project leopard by tanhaichao.
the class LeopardBeanFactoryAware method getSingleBean.
public static <T> T getSingleBean(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());
}
use of org.springframework.context.annotation.Primary in project commons-dao by reportportal.
the class DatabaseConfiguration method transactionManager.
@Bean
@Primary
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory());
return transactionManager;
}
use of org.springframework.context.annotation.Primary in project spring-boot by spring-projects.
the class JmxAutoConfiguration method mbeanExporter.
@Bean
@Primary
@ConditionalOnMissingBean(value = MBeanExporter.class, search = SearchStrategy.CURRENT)
public AnnotationMBeanExporter mbeanExporter(ObjectNamingStrategy namingStrategy) {
AnnotationMBeanExporter exporter = new AnnotationMBeanExporter();
exporter.setRegistrationPolicy(RegistrationPolicy.FAIL_ON_EXISTING);
exporter.setNamingStrategy(namingStrategy);
String server = this.propertyResolver.getProperty("server", "mbeanServer");
if (StringUtils.hasLength(server)) {
exporter.setServer(this.beanFactory.getBean(server, MBeanServer.class));
}
return exporter;
}
Aggregations