List of usage examples for org.springframework.beans.factory.annotation QualifierAnnotationAutowireCandidateResolver QualifierAnnotationAutowireCandidateResolver
@SuppressWarnings("unchecked") public QualifierAnnotationAutowireCandidateResolver()
From source file:com.geodevv.testing.irmina.IrminaApplicationContext.java
@Inject public IrminaApplicationContext(IrminaListableBeanFactory beanFactory) { this.beanFactory = beanFactory; this.beanFactory.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); }
From source file:ch.nydi.spring.context.support.TestGenericXmlContextLoader.java
/** * {@inheritDoc}/*from w w w . ja va 2 s. c o m*/ */ @Override public final ConfigurableApplicationContext loadContext(final String... locations) throws Exception { final DefaultListableBeanFactory beanFactory = new PrimaryResolverListableBeanFactory(); beanFactory.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer()); beanFactory.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); final GenericApplicationContext context = new GenericApplicationContext(beanFactory); createBeanDefinitionReader(context).loadBeanDefinitions(locations); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.exoplatform.container.spring.SpringContainer.java
/** * {@inheritDoc}/*from w w w. ja v a 2s . co m*/ */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void start() { ConfigurationManager cm = super.getComponentInstanceOfType(ConfigurationManager.class, false); // We check if the component has been defined in the configuration of the current container // The goal is to enable the SpringContainer only if it is needed Component component = cm.getComponent(ApplicationContextProvider.class); if (component == null) { if (LOG.isDebugEnabled()) { LOG.debug( "No ApplicationContextProvider has been defined, thus the SpringContainer will be disabled." + " To enable the Spring Integration please define an ApplicationContextProvider"); } } else { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); Collection<ComponentAdapter<?>> adapters = delegate.getComponentAdapters(); for (ComponentAdapter<?> adapter : adapters) { Object key = adapter.getComponentKey(); String name = keyToBeanName(key); String factoryName = name + "#factory"; RootBeanDefinition def = new RootBeanDefinition(adapter.getComponentImplementation(), AbstractBeanDefinition.AUTOWIRE_NO, false); def.setScope(BeanDefinition.SCOPE_PROTOTYPE); def.setFactoryBeanName(factoryName); def.setFactoryMethodName("getInstance"); def.setLazyInit(true); def.setTargetType(adapter.getComponentImplementation()); if (key instanceof String) { def.addQualifier(new AutowireCandidateQualifier(Named.class, key)); } else if (key instanceof Class<?> && ((Class<?>) key).isAnnotation()) { def.addQualifier(new AutowireCandidateQualifier((Class<?>) key)); } else { def.setPrimary(true); } bf.registerBeanDefinition(name, def); bf.registerSingleton(factoryName, new ComponentAdapterFactoryBean(adapter)); } GenericApplicationContext parentContext = new GenericApplicationContext(bf); parentContext.refresh(); ApplicationContextProvider provider = super.getComponentInstanceOfType(ApplicationContextProvider.class, false); ctx = provider.getApplicationContext(parentContext); LOG.info("A SpringContainer has been enabled using the ApplicationContextProvider " + provider.getClass()); } super.start(); }