List of usage examples for org.springframework.beans.factory.annotation BeanFactoryAnnotationUtils qualifiedBeanOfType
private static <T> T qualifiedBeanOfType(ListableBeanFactory bf, Class<T> beanType, String qualifier)
From source file:com.github.ljtfreitas.restify.spring.netflix.autoconfigure.hystrix.HystrixFallbackBeanFactory.java
private Object doSearch(Class<?> classType) { try {//w ww. j ava 2 s.c om return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, classType, QUALIFIER_NAME); } catch (NoSuchBeanDefinitionException e) { return null; } }
From source file:org.springframework.aop.interceptor.AsyncExecutionAspectSupport.java
/** * Retrieve a target executor for the given qualifier. * @param qualifier the qualifier to resolve * @return the target executor, or {@code null} if none available * @since 4.2.6// w w w .j a va2s . c o m * @see #getExecutorQualifier(Method) */ @Nullable protected Executor findQualifiedExecutor(@Nullable BeanFactory beanFactory, String qualifier) { if (beanFactory == null) { throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() + " to access qualified executor '" + qualifier + "'"); } return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, Executor.class, qualifier); }
From source file:org.springframework.cache.interceptor.CacheAspectSupport.java
/** * Return a bean with the specified name and type. Used to resolve services that * are referenced by name in a {@link CacheOperation}. * @param beanName the name of the bean, as defined by the operation * @param expectedType type for the bean * @return the bean matching that name//from w ww .j a va 2 s . c o m * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist * @see CacheOperation#keyGenerator * @see CacheOperation#cacheManager * @see CacheOperation#cacheResolver */ protected <T> T getBean(String beanName, Class<T> expectedType) { if (this.beanFactory == null) { throw new IllegalStateException( "BeanFactory must be set on cache aspect for " + expectedType.getSimpleName() + " retrieval"); } return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, expectedType, beanName); }
From source file:org.springframework.test.context.transaction.TransactionalTestExecutionListener.java
/** * Get the {@linkplain PlatformTransactionManager transaction manager} to use * for the supplied {@linkplain TestContext test context} and {@code qualifier}. * <p>Delegates to {@link #getTransactionManager(TestContext)} if the * supplied {@code qualifier} is {@code null} or empty. * @param testContext the test context for which the transaction manager * should be retrieved/* w ww. j a va 2 s . co m*/ * @param qualifier the qualifier for selecting between multiple bean matches; * may be {@code null} or empty * @return the transaction manager to use, or {@code null} if not found * @throws BeansException if an error occurs while retrieving the transaction manager * @see #getTransactionManager(TestContext) */ @Nullable protected PlatformTransactionManager getTransactionManager(TestContext testContext, @Nullable String qualifier) { // Look up by type and qualifier from @Transactional if (StringUtils.hasText(qualifier)) { try { // Use autowire-capable factory in order to support extended qualifier matching // (only exposed on the internal BeanFactory, not on the ApplicationContext). BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory(); return BeanFactoryAnnotationUtils.qualifiedBeanOfType(bf, PlatformTransactionManager.class, qualifier); } catch (RuntimeException ex) { if (logger.isWarnEnabled()) { logger.warn(String.format( "Caught exception while retrieving transaction manager with qualifier '%s' for test context %s", qualifier, testContext), ex); } throw ex; } } // else return getTransactionManager(testContext); }
From source file:org.springframework.transaction.interceptor.TransactionAspectSupport.java
private PlatformTransactionManager determineQualifiedTransactionManager(BeanFactory beanFactory, String qualifier) {//from ww w . j av a 2 s . c om PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier); if (txManager == null) { txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, PlatformTransactionManager.class, qualifier); this.transactionManagerCache.putIfAbsent(qualifier, txManager); } return txManager; }