Java 类org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils 实例源码

项目:lams    文件:TransactionAspectSupport.java   
/**
 * Determine the specific transaction manager to use for the given transaction.
 */
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
    if (this.transactionManager != null || this.beanFactory == null || txAttr == null) {
        return this.transactionManager;
    }
    String qualifier = txAttr.getQualifier();
    if (StringUtils.hasLength(qualifier)) {
        return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, PlatformTransactionManager.class, qualifier);
    }
    else if (this.transactionManagerBeanName != null) {
        return this.beanFactory.getBean(this.transactionManagerBeanName, PlatformTransactionManager.class);
    }
    else {
        return this.beanFactory.getBean(PlatformTransactionManager.class);
    }
}
项目:lams    文件:AsyncExecutionAspectSupport.java   
/**
 * Determine the specific executor to use when executing the given method.
 * @return the executor to use (or {@code null}, but just if no default executor has been set)
 */
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
        Executor executorToUse = this.defaultExecutor;
        String qualifier = getExecutorQualifier(method);
        if (StringUtils.hasLength(qualifier)) {
            Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
                    " to access qualified executor '" + qualifier + "'");
            executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
                    this.beanFactory, Executor.class, qualifier);
        }
        else if (executorToUse == null) {
            return null;
        }
        executor = (executorToUse instanceof AsyncTaskExecutor ?
                (AsyncTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
        this.executors.put(method, executor);
    }
    return executor;
}
项目:spring4-understanding    文件:AsyncExecutionAspectSupport.java   
/**
 * Determine the specific executor to use when executing the given method.
 * Should preferably return an {@link AsyncListenableTaskExecutor} implementation.
 * @return the executor to use (or {@code null}, but just if no default executor has been set)
 */
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
        Executor executorToUse = this.defaultExecutor;
        String qualifier = getExecutorQualifier(method);
        if (StringUtils.hasLength(qualifier)) {
            if (this.beanFactory == null) {
                throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
                        " to access qualified executor '" + qualifier + "'");
            }
            executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
                    this.beanFactory, Executor.class, qualifier);
        }
        else if (executorToUse == null) {
            return null;
        }
        executor = (executorToUse instanceof AsyncListenableTaskExecutor ?
                (AsyncListenableTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
        this.executors.put(method, executor);
    }
    return executor;
}
项目:spring4-understanding    文件: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
 * @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)
 */
protected PlatformTransactionManager getTransactionManager(TestContext testContext, 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);
}
项目:konker-platform    文件:DeviceEventProcessor.java   
private String getJsonPayload(Device device, byte[] payloadBytes) throws BusinessException {

        DeviceModel.ContentType contentType = device.getDeviceModel().getContentType();
        if (contentType == null) {
            contentType = DeviceModel.ContentType.APPLICATION_JSON;
        }

        JsonConverter jsonConverter = BeanFactoryAnnotationUtils.qualifiedBeanOfType(beans, JsonConverter.class, contentType.getValue());
        ServiceResponse<String> jsonConverterResponse = jsonConverter.toJson(payloadBytes);

        if (jsonConverterResponse.isOk()) {
            return jsonConverterResponse.getResult();
        } else {
            throw new BusinessException(Messages.INVALID_PAYLOAD.getCode());
        }

    }
项目:class-guard    文件:AsyncExecutionAspectSupport.java   
/**
 * Determine the specific executor to use when executing the given method.
 * @return the executor to use (or {@code null}, but just if no default executor has been set)
 */
protected AsyncTaskExecutor determineAsyncExecutor(Method method) {
    AsyncTaskExecutor executor = this.executors.get(method);
    if (executor == null) {
        Executor executorToUse = this.defaultExecutor;
        String qualifier = getExecutorQualifier(method);
        if (StringUtils.hasLength(qualifier)) {
            Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
                    " to access qualified executor '" + qualifier + "'");
            executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
                    this.beanFactory, Executor.class, qualifier);
        }
        else if (executorToUse == null) {
            return null;
        }
        executor = (executorToUse instanceof AsyncTaskExecutor ?
                (AsyncTaskExecutor) executorToUse : new TaskExecutorAdapter(executorToUse));
        this.executors.put(method, executor);
    }
    return executor;
}
项目:class-guard    文件:TransactionAspectSupport.java   
/**
 * Determine the specific transaction manager to use for the given transaction.
 */
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
    if (this.transactionManager != null || this.beanFactory == null || txAttr == null) {
        return this.transactionManager;
    }
    String qualifier = txAttr.getQualifier();
    if (StringUtils.hasLength(qualifier)) {
        return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, PlatformTransactionManager.class, qualifier);
    }
    else if (this.transactionManagerBeanName != null) {
        return this.beanFactory.getBean(this.transactionManagerBeanName, PlatformTransactionManager.class);
    }
    else {
        return this.beanFactory.getBean(PlatformTransactionManager.class);
    }
}
项目:class-guard    文件:TransactionalTestExecutionListener.java   
/**
 * Get the {@link PlatformTransactionManager transaction manager} to use
 * for the supplied {@link 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
 * @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)
 */
protected final PlatformTransactionManager getTransactionManager(TestContext testContext, 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("Caught exception while retrieving transaction manager for test context " + testContext
                        + " and qualifier [" + qualifier + "]", ex);
            }
            throw ex;
        }
    }

    // else
    return getTransactionManager(testContext);
}
项目:spring4-understanding    文件:TransactionAspectSupport.java   
private PlatformTransactionManager determineQualifiedTransactionManager(String qualifier) {
    PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier);
    if (txManager == null) {
        txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
                this.beanFactory, PlatformTransactionManager.class, qualifier);
        this.transactionManagerCache.putIfAbsent(qualifier, txManager);
    }
    return txManager;
}
项目:konker-platform    文件:EventPublisherDevice.java   
private ServiceResponse<byte[]> getJsonPayload(Device device, String payloadJson) {

        DeviceModel.ContentType contentType = DeviceModel.ContentType.APPLICATION_JSON;
        if (device.getDeviceModel() != null &&
            device.getDeviceModel().getContentType() != null) {
            contentType = device.getDeviceModel().getContentType();
        }

        JsonConverter jsonConverter = BeanFactoryAnnotationUtils.qualifiedBeanOfType(beans, JsonConverter.class, contentType.getValue());
        ServiceResponse<byte[]> jsonConverterResponse = jsonConverter.fromJson(payloadJson);

        return jsonConverterResponse;

    }
项目:java-restify    文件:HystrixFallbackBeanFactory.java   
private Object doSearch(Class<?> classType) {
    try {
        return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, classType, QUALIFIER_NAME);
    } catch (NoSuchBeanDefinitionException e) {
        return null;
    }
}
项目:spring    文件: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
 * @see #getExecutorQualifier(Method)
 */
protected Executor findQualifiedExecutor(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);
}
项目:ldtm    文件:AnnotationLdtmAttributeSource.java   
private PlatformTransactionManager determineQualifiedTransactionManager(String qualifier) {
    PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier);
    if (txManager == null) {
        txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
                this.beanFactory, PlatformTransactionManager.class, qualifier);
        this.transactionManagerCache.putIfAbsent(qualifier, txManager);
    }

    return txManager;
}
项目:Qihua    文件: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 type for the bean
 * @return the bean matching that name
 * @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) {
  return BeanFactoryAnnotationUtils.qualifiedBeanOfType(applicationContext, expectedType, beanName);
}
项目:spring4-understanding    文件: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 type for the bean
 * @return the bean matching that name
 * @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) {
    return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.applicationContext, expectedType, beanName);
}
项目:spring    文件: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
 * @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) {
    return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, expectedType, beanName);
}
项目:class-guard    文件:TransactionAspectUtils.java   
/**
 * Obtain a PlatformTransactionManager from the given BeanFactory, matching the given qualifier.
 * @param beanFactory the BeanFactory to get the {@code PlatformTransactionManager} bean from
 * @param qualifier the qualifier for selecting between multiple {@code PlatformTransactionManager} matches
 * @return the chosen {@code PlatformTransactionManager} (never {@code null})
 * @throws IllegalStateException if no matching {@code PlatformTransactionManager} bean found
 * @deprecated as of Spring 3.1.2 in favor of
 * {@link BeanFactoryAnnotationUtils#qualifiedBeanOfType(BeanFactory, Class, String)}
 */
@Deprecated
public static PlatformTransactionManager getTransactionManager(BeanFactory beanFactory, String qualifier) {
    return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, PlatformTransactionManager.class, qualifier);
}
项目:class-guard    文件:TransactionAspectUtils.java   
/**
 * Obtain a PlatformTransactionManager from the given BeanFactory, matching the given qualifier.
 * @param bf the BeanFactory to get the {@code PlatformTransactionManager} bean from
 * @param qualifier the qualifier for selecting between multiple {@code PlatformTransactionManager} matches
 * @return the chosen {@code PlatformTransactionManager} (never {@code null})
 * @throws IllegalStateException if no matching {@code PlatformTransactionManager} bean found
 * @deprecated as of Spring 3.1.2 in favor of
 * {@link BeanFactoryAnnotationUtils#qualifiedBeanOfType(BeanFactory, Class, String)}
 */
@Deprecated
public static PlatformTransactionManager getTransactionManager(ConfigurableListableBeanFactory bf, String qualifier) {
    return BeanFactoryAnnotationUtils.qualifiedBeanOfType(bf, PlatformTransactionManager.class, qualifier);
}