Java 类org.springframework.beans.factory.support.AutowireCandidateResolver 实例源码

项目:kc-rice    文件:DefaultListableBeanFactory.java   
/**
 * Set a custom autowire candidate resolver for this BeanFactory to use
 * when deciding whether a bean definition should be considered as a
 * candidate for autowiring.
 */
public void setAutowireCandidateResolver(final AutowireCandidateResolver autowireCandidateResolver) {
    Assert.notNull(autowireCandidateResolver, "AutowireCandidateResolver must not be null");
    if (autowireCandidateResolver instanceof BeanFactoryAware) {
        if (System.getSecurityManager() != null) {
            final BeanFactory target = this;
            AccessController.doPrivileged(new PrivilegedAction<Object>() {
                public Object run() {
                    ((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(target);
                    return null;
                }
            }, getAccessControlContext());
        }
        else {
            ((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(this);
        }
    }
    this.autowireCandidateResolver = autowireCandidateResolver;
}
项目:loginject    文件:SpringLogInjectionService.java   
@Override
public BeanFactoryPostProcessor getBindings(LogInject<_Logger_> logInject)
{
    return new BeanFactoryPostProcessor()
    {
        ThreadLocal<Object> injectee = new ThreadLocal<>();

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
        {
            DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory)beanFactory;
            AutowireCandidateResolver resolver = new ContextAnnotationAutowireCandidateResolver()
            {
                @Override
                public Object getSuggestedValue(DependencyDescriptor descriptor)
                {
                    if (descriptor.getDependencyType().equals(logInject.getLoggerClass()))
                    {
                        return logInject.createLogger(injectee.get().getClass());
                    }
                    return null;
                }
            };
            AutowiredAnnotationBeanPostProcessor beanPostProcessor = new AutowiredAnnotationBeanPostProcessor()
            {
                @Override
                public PropertyValues postProcessPropertyValues(PropertyValues values, PropertyDescriptor[] descriptors,
                    Object bean, String beanName) throws BeansException
                {
                    injectee.set(bean);
                    return super.postProcessPropertyValues(values, descriptors, bean, beanName);
                }
            };
            beanPostProcessor.setBeanFactory(defaultListableBeanFactory);
            defaultListableBeanFactory.addBeanPostProcessor(beanPostProcessor);
            defaultListableBeanFactory.setAutowireCandidateResolver(resolver);
        }
    };
}
项目:gen-sbconfigurator    文件:SpringHelper.java   
/**
 * Creates a <code>DefaultListableBeanFactory</code> with some default
 * settings, i.e.
 * <ul>
 * <li>support of auto-wiring annotation</li>
 * <li>disabled bean-overriding</li>
 * </ul>
 * 
 * @param enableAutoWiring
 *            <code>true</code> if auto-wiring for the factory should be
 *            enabled, otherwise <code>false</code>
 * @param allowBeanOverriding
 *            <code>true</code> if a bean can override another bean with the
 *            same id, otherwise <code>false</code>
 * 
 * @return a <code>DefaultListableBeanFactory</code> with some default
 *         settings
 * 
 * @see AutowiredAnnotationBeanPostProcessor
 * @see DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
 */
public static DefaultListableBeanFactory createBeanFactory(
        final boolean enableAutoWiring, final boolean allowBeanOverriding) {

    // create the factory
    final DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.setAllowBeanDefinitionOverriding(allowBeanOverriding);

    // enable auto-wiring
    if (enableAutoWiring) {
        // get the resolver used for autowiring, we want the qualifier to be
        // used
        // when resolving
        final AutowireCandidateResolver resolver = new QualifierAnnotationAutowireCandidateResolver();
        factory.setAutowireCandidateResolver(resolver);

        // now create the post processor and set the factory and the
        // resolver
        final AutowiredAnnotationBeanPostProcessor autowiredPostProcessor = new AutowiredAnnotationBeanPostProcessor();
        autowiredPostProcessor.setBeanFactory(factory);
        factory.addBeanPostProcessor(autowiredPostProcessor);
    }

    factory.addPropertyEditorRegistrar(new ConfiguratorPropertyEditorRegistrar());

    return factory;
}
项目:kc-rice    文件:DefaultListableBeanFactory.java   
/**
 * Return the autowire candidate resolver for this BeanFactory (never {@code null}).
 */
public AutowireCandidateResolver getAutowireCandidateResolver() {
    return this.autowireCandidateResolver;
}
项目:resteeth    文件:ResteethAutowireCandidateResolverDelegate.java   
public ResteethAutowireCandidateResolverDelegate(AutowireCandidateResolver autowireCandidateResolver,
                                                 AnnotationAttributes enableResteethAttributes) {
    this.autowireCandidateResolver = autowireCandidateResolver;
    this.enableResteethAttributes = enableResteethAttributes;
}