Java 类org.springframework.beans.factory.config.BeanFactoryPostProcessor 实例源码

项目:gemini.blueprint    文件:BaseMetadataTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();
    applicationContext = new GenericApplicationContext();
    applicationContext.setClassLoader(getClass().getClassLoader());
    applicationContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    applicationContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
        }
    });
    reader = new XmlBeanDefinitionReader(applicationContext);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(getConfig(), getClass()));
    applicationContext.refresh();
    blueprintContainer = new SpringBlueprintContainer(applicationContext);
}
项目:gemini.blueprint    文件:NestedDefinitionMetadataTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
        }
    });

    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    blueprintContainer = new SpringBlueprintContainer(context);
}
项目:gemini.blueprint    文件:TestLazyBeansTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
            beanFactory.registerSingleton("blueprintContainer",
                    new SpringBlueprintContainer(context));
        }
    });

    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    blueprintContainer = new SpringBlueprintContainer(context);
}
项目:gemini.blueprint    文件:LazyExporterTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
        }
    });

    reader = new XmlBeanDefinitionReader(context);
    reader.setDocumentLoader(new PublicBlueprintDocumentLoader());
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    blueprintContainer = new SpringBlueprintContainer(context);
}
项目:saluki    文件:MonitorAutoconfiguration.java   
@Bean
public BeanFactoryPostProcessor beanFactoryPostProcessor(ApplicationContext applicationContext) {
    return new BeanFactoryPostProcessor() {

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            if (beanFactory instanceof BeanDefinitionRegistry) {
                try {
                    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
                    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry);
                    scanner.setResourceLoader(applicationContext);
                    scanner.scan("com.quancheng.saluki.boot.web");
                } catch (Throwable e) {
                    log.error(e.getMessage(), e);
                }
            }

        }

    };
}
项目:springmock    文件:ApplicationContextCreator.java   
public static ApplicationContext buildAppContext(ApplicationContext parent, Stream<TestBean> beans, Collection<BeanFactoryPostProcessor> postProcessors) {
    final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    final GenericApplicationContext applicationContext = new GenericApplicationContext(beanFactory, parent);

    postProcessors.forEach(applicationContext::addBeanFactoryPostProcessor);

    beans.forEach(entry -> {
        final String factoryBean = entry.getName() + "_factory";
        beanFactory.registerSingleton(factoryBean, (Supplier<Object>) entry::getBean);
        beanFactory.registerBeanDefinition(entry.getName(), BeanDefinitionBuilder
                .rootBeanDefinition(entry.getBean() != null ? entry.getBean().getClass() : Object.class)
                .setFactoryMethodOnBean("get", factoryBean)
                .getBeanDefinition());
    });

    applicationContext.refresh();

    return applicationContext;
}
项目:spring4-understanding    文件:FactoryBeanTests.java   
@Test
public void testFactoryBeansWithAutowiring() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

    BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
    ppc.postProcessBeanFactory(factory);

    assertNull(factory.getType("betaFactory"));

    Alpha alpha = (Alpha) factory.getBean("alpha");
    Beta beta = (Beta) factory.getBean("beta");
    Gamma gamma = (Gamma) factory.getBean("gamma");
    Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");

    assertSame(beta, alpha.getBeta());
    assertSame(gamma, beta.getGamma());
    assertSame(gamma2, beta.getGamma());
    assertEquals("yourName", beta.getName());
}
项目:graviteeio-access-management    文件:SpringServletContext.java   
protected WebApplicationContext applicationContext() {
    if (applicationContext == null) {
        AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();

        Set<Class<?>> annotatedClasses = annotatedClasses();
        if (annotatedClasses != null) {
            annotatedClasses.iterator().forEachRemaining(webApplicationContext::register);
        }

        Set<? extends BeanFactoryPostProcessor> beanFactoryPostProcessors = beanFactoryPostProcessors();
        if (beanFactoryPostProcessors != null) {
            beanFactoryPostProcessors.iterator().forEachRemaining(webApplicationContext::addBeanFactoryPostProcessor);
        }

        if (this.rootApplicationContext != null) {
            webApplicationContext.setParent(this.rootApplicationContext);
            webApplicationContext.setEnvironment((ConfigurableEnvironment) rootApplicationContext.getEnvironment());
        }

        applicationContext = webApplicationContext;
    }

    return (WebApplicationContext) applicationContext;
}
项目:joinfaces    文件:JsfScopeAnnotationsAutoConfiguration.java   
@Bean
@ConditionalOnProperty(value = "jsf.scope-configurer.jsf.enabled", havingValue = "true", matchIfMissing = true)
public static BeanFactoryPostProcessor jsfScopeAnnotationsConfigurer(Environment environment) {
    CustomScopeAnnotationConfigurer scopeAnnotationConfigurer = new CustomScopeAnnotationConfigurer();

    scopeAnnotationConfigurer.setOrder(environment.getProperty("jsf.scope-configurer.jsf.order", Integer.class, Ordered.LOWEST_PRECEDENCE));

    scopeAnnotationConfigurer.addMapping(NoneScoped.class, ConfigurableBeanFactory.SCOPE_PROTOTYPE);
    scopeAnnotationConfigurer.addMapping(RequestScoped.class, WebApplicationContext.SCOPE_REQUEST);
    scopeAnnotationConfigurer.addMapping(javax.faces.bean.ViewScoped.class, ViewScope.SCOPE_VIEW);
    scopeAnnotationConfigurer.addMapping(javax.faces.view.ViewScoped.class, ViewScope.SCOPE_VIEW);
    scopeAnnotationConfigurer.addMapping(SessionScoped.class, WebApplicationContext.SCOPE_SESSION);
    scopeAnnotationConfigurer.addMapping(ApplicationScoped.class, WebApplicationContext.SCOPE_APPLICATION);

    return scopeAnnotationConfigurer;
}
项目:resteasy-spring-boot    文件:ResteasyAutoConfigurationTest.java   
private void testServletContextListener(ServletContext servletContext) throws Exception {
    ResteasyAutoConfiguration resteasyAutoConfiguration = new ResteasyAutoConfiguration();
    BeanFactoryPostProcessor beanFactoryPostProcessor = ResteasyAutoConfiguration.springBeanProcessor();
    ServletContextListener servletContextListener = resteasyAutoConfiguration.resteasyBootstrapListener(beanFactoryPostProcessor);
    Assert.assertNotNull(servletContextListener);

    ServletContextEvent sce = new ServletContextEvent(servletContext);
    servletContextListener.contextInitialized(sce);

    ResteasyProviderFactory servletContextProviderFactory = (ResteasyProviderFactory) servletContext.getAttribute(ResteasyProviderFactory.class.getName());
    Dispatcher servletContextDispatcher = (Dispatcher) servletContext.getAttribute(Dispatcher.class.getName());
    Registry servletContextRegistry = (Registry) servletContext.getAttribute(Registry.class.getName());

    Assert.assertNotNull(servletContextProviderFactory);
    Assert.assertNotNull(servletContextDispatcher);
    Assert.assertNotNull(servletContextRegistry);

    // Exercising fully cobertura branch coverage
    servletContextListener.contextDestroyed(sce);
    ServletContextListener servletContextListener2 = resteasyAutoConfiguration.resteasyBootstrapListener(beanFactoryPostProcessor);
    servletContextListener2.contextDestroyed(sce);
}
项目:class-guard    文件:FactoryBeanTests.java   
@Test
public void testFactoryBeansWithAutowiring() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

    BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
    ppc.postProcessBeanFactory(factory);

    Alpha alpha = (Alpha) factory.getBean("alpha");
    Beta beta = (Beta) factory.getBean("beta");
    Gamma gamma = (Gamma) factory.getBean("gamma");
    Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");
    assertSame(beta, alpha.getBeta());
    assertSame(gamma, beta.getGamma());
    assertSame(gamma2, beta.getGamma());
    assertEquals("yourName", beta.getName());
}
项目:spring-cloud-aws    文件:ContextInstanceDataPropertySourceBeanDefinitionParserTest.java   
@Test
public void parseInternal_singleElementDefined_beanDefinitionCreated() throws Exception {
    //Arrange
    HttpServer httpServer = MetaDataServer.setupHttpServer();
    HttpContext instanceIdHttpContext = httpServer.createContext("/latest/meta-data/instance-id", new MetaDataServer.HttpResponseWriterHandler("testInstanceId"));
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

    //Act
    reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));

    //Assert
    BeanFactoryPostProcessor postProcessor = beanFactory.getBean("AmazonEc2InstanceDataPropertySourcePostProcessor", BeanFactoryPostProcessor.class);
    assertNotNull(postProcessor);
    assertEquals(1, beanFactory.getBeanDefinitionCount());

    httpServer.removeContext(instanceIdHttpContext);
}
项目:message-cowboy    文件:ProductionPropertyOverrides.java   
/**
 * Overrides properties configured on beans.
 */
@Bean()
@Lazy(false)
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public static BeanFactoryPostProcessor propertyOverrideConfigurer() {
    PropertyOverrideConfigurer theOverrideConfigurer = new PropertyOverrideConfigurer();

    final Properties thePropertiesHolder = new Properties();
    /* Task refresh interval. */
    thePropertiesHolder.put("starterService.taskReschedulingCronExpression", "0/20 * * * * ?");
    /* Transport service configuration refresh interval. */
    thePropertiesHolder.put("starterService.transportServiceConfigurationRefreshCronExpression", "0/30 * * * * ?");
    /* Task execution status reports cleanup interval. */
    thePropertiesHolder.put("starterService.taskExecutionStatusCleanupCronExpression", "0/30 0/15 * * * ?");

    theOverrideConfigurer.setProperties(thePropertiesHolder);
    theOverrideConfigurer.setIgnoreInvalidKeys(false);
    theOverrideConfigurer.setIgnoreResourceNotFound(false);
    theOverrideConfigurer.setOrder(0);
    return theOverrideConfigurer;
}
项目:message-cowboy    文件:TaskExecutionStatusCleanupTestConfiguration.java   
/**
 * Overrides properties configured on beans.
 */
@Bean()
@Lazy(false)
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public static BeanFactoryPostProcessor propertyOverrideConfigurer() {
    PropertyOverrideConfigurer theOverrideConfigurer = new PropertyOverrideConfigurer();

    final Properties thePropertiesHolder = new Properties();
    /* Task refresh interval. */
    thePropertiesHolder.put("starterService.taskReschedulingCronExpression", "* 4/30 * * * ?");
    /* Transport service configuration refresh interval. */
    thePropertiesHolder.put("starterService.transportServiceConfigurationRefreshCronExpression", "* 5/30 * * * ?");
    /* Task execution status reports cleanup interval. */
    thePropertiesHolder.put("starterService.taskExecutionStatusCleanupCronExpression", "0/5 * * * * ?");

    theOverrideConfigurer.setProperties(thePropertiesHolder);
    theOverrideConfigurer.setIgnoreInvalidKeys(false);
    theOverrideConfigurer.setIgnoreResourceNotFound(false);
    theOverrideConfigurer.setOrder(0);
    return theOverrideConfigurer;
}
项目:gemini.blueprint    文件:BlueprintContainerProcessor.java   
public BlueprintContainerProcessor(EventAdminDispatcher dispatcher, BlueprintListenerManager listenerManager,
        Bundle extenderBundle) {
    this.dispatcher = dispatcher;
    this.listenerManager = listenerManager;
    this.extenderBundle = extenderBundle;

    Class<?> processorClass =
            ClassUtils.resolveClassName(
                    "org.eclipse.gemini.blueprint.blueprint.container.support.internal.config.CycleOrderingProcessor",
                    BundleContextAware.class.getClassLoader());

    cycleBreaker = (BeanFactoryPostProcessor) BeanUtils.instantiate(processorClass);
}
项目:gemini.blueprint    文件:AbstractDelegatedExecutionApplicationContext.java   
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
        Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

    for (BeanFactoryPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessBeanFactory(beanFactory);
    }
}
项目:gemini.blueprint    文件:ComponentSubElementTest.java   
protected void setUp() throws Exception {
    bundleContext = new MockBundleContext();

    context = new GenericApplicationContext();
    context.setClassLoader(getClass().getClassLoader());
    context.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
    context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            beanFactory.addPropertyEditorRegistrar(new BlueprintEditorRegistrar());
        }
    });

    reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(new ClassPathResource(CONFIG, getClass()));
    context.refresh();

    BlueprintContainer = new SpringBlueprintContainer(context);
}
项目:lams    文件:PostProcessorRegistrationDelegate.java   
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
        Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

    for (BeanFactoryPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessBeanFactory(beanFactory);
    }
}
项目:spring4-understanding    文件:PostProcessorRegistrationDelegate.java   
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
        Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

    for (BeanFactoryPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessBeanFactory(beanFactory);
    }
}
项目:spring4-understanding    文件:ConfigurationClassProcessingTests.java   
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
    return new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
            BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
            bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
        }
    };
}
项目:spring4-understanding    文件:ConfigurationClassAndBFPPTests.java   
@Bean
public BeanFactoryPostProcessor bfpp() {
    return new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            // no-op
        }
    };
}
项目:spring4-understanding    文件:ConfigurationClassAndBFPPTests.java   
@Bean
public static final BeanFactoryPostProcessor bfpp() {
    return new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            // no-op
        }
    };
}
项目:spring4-understanding    文件:FactoryBeanTests.java   
@Test
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

    BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
    ppc.postProcessBeanFactory(factory);

    Beta beta = (Beta) factory.getBean("beta");
    Alpha alpha = (Alpha) factory.getBean("alpha");
    Gamma gamma = (Gamma) factory.getBean("gamma");
    assertSame(beta, alpha.getBeta());
    assertSame(gamma, beta.getGamma());
}
项目:my-spring-cache-redis    文件:PostProcessorRegistrationDelegate.java   
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
        Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

    for (BeanFactoryPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessBeanFactory(beanFactory);
    }
}
项目:joinfaces    文件:CdiScopeAnnotationsAutoConfiguration.java   
@Bean
@ConditionalOnProperty(value = "jsf.scope-configurer.cdi.enabled", havingValue = "true", matchIfMissing = true)
public static BeanFactoryPostProcessor cdiScopeAnnotationsConfigurer(Environment environment) {
    CustomScopeAnnotationConfigurer scopeAnnotationConfigurer = new CustomScopeAnnotationConfigurer();

    scopeAnnotationConfigurer.setOrder(environment.getProperty("jsf.scope-configurer.cdi.order", Integer.class, Ordered.LOWEST_PRECEDENCE));

    scopeAnnotationConfigurer.addMapping(RequestScoped.class, WebApplicationContext.SCOPE_REQUEST);
    scopeAnnotationConfigurer.addMapping(SessionScoped.class, WebApplicationContext.SCOPE_SESSION);
    scopeAnnotationConfigurer.addMapping(ConversationScoped.class, WebApplicationContext.SCOPE_SESSION);
    scopeAnnotationConfigurer.addMapping(ApplicationScoped.class, WebApplicationContext.SCOPE_APPLICATION);

    return scopeAnnotationConfigurer;
}
项目:joinfaces    文件:ViewScopeAutoConfigurationTest.java   
@Test
public void testRegisteredScopeView() {
    ConfigurableListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    BeanFactoryPostProcessor beanFactoryPostProcessor = ViewScopeAutoConfiguration.viewScopeConfigurer();

    beanFactoryPostProcessor.postProcessBeanFactory(beanFactory);

    assertThat(beanFactory.getRegisteredScope(ViewScope.SCOPE_VIEW))
            .isInstanceOf(ViewScope.class);
}
项目:spring    文件:PostProcessorRegistrationDelegate.java   
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
        Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

    for (BeanFactoryPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessBeanFactory(beanFactory);
    }
}
项目:dxa-modules    文件:ExtractorsTest.java   
@Bean
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
    return new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            doMapping("os.model", "", mockProcessor("Windows"), beanFactory);
            doMapping("browser.model", "", mockProcessor("Chrome"), beanFactory);
            doMapping("browser.type", "", mockProcessor("Desktop"), beanFactory);
            doMapping("browser.version", "", mockProcessor(49), beanFactory);
        }
    };
}
项目:spring-cloud-stream    文件:SchemaServerConfiguration.java   
@Bean
public static BeanFactoryPostProcessor entityScanPackagesPostProcessor() {
    return new BeanFactoryPostProcessor() {

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            if (beanFactory instanceof BeanDefinitionRegistry) {
                EntityScanPackages.register((BeanDefinitionRegistry) beanFactory,
                        Collections.singletonList(Schema.class.getPackage().getName()));
            }
        }
    };
}
项目:sakai    文件:SakaiApplicationContext.java   
/**
 * Add bean-created post processors.
 * @param beanFactory
 */
public void invokePostProcessorCreators(ConfigurableListableBeanFactory beanFactory) {
    String[] postProcessorCreatorNames = beanFactory.getBeanNamesForType(BeanFactoryPostProcessorCreator.class, false, false);
    for (int i = 0; i < postProcessorCreatorNames.length; i++) {
        BeanFactoryPostProcessorCreator postProcessorCreator = (BeanFactoryPostProcessorCreator)beanFactory.getBean(postProcessorCreatorNames[i]);
        for (BeanFactoryPostProcessor beanFactoryPostProcessor : postProcessorCreator.getBeanFactoryPostProcessors()) {
            addBeanFactoryPostProcessor(beanFactoryPostProcessor);
        }
    }
}
项目: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);
        }
    };
}
项目:spring-struts-forwardport    文件:ContextLoaderPlugIn.java   
/**
 * Instantiate the WebApplicationContext for the ActionServlet, either a default
 * XmlWebApplicationContext or a custom context class if set.
 * <p>This implementation expects custom contexts to implement ConfigurableWebApplicationContext.
 * Can be overridden in subclasses.
 * @throws org.springframework.beans.BeansException if the context couldn't be initialized
 * @see #setContextClass
 * @see org.springframework.web.context.support.XmlWebApplicationContext
 */
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
        throws BeansException {

    if (logger.isDebugEnabled()) {
        logger.debug("ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
                "', module '" + getModulePrefix() + "' will try to create custom WebApplicationContext " +
                "context of class '" + getContextClass().getName() + "', using parent context [" + parent + "]");
    }
    if (!ConfigurableWebApplicationContext.class.isAssignableFrom(getContextClass())) {
        throw new ApplicationContextException(
                "Fatal initialization error in ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
                "', module '" + getModulePrefix() + "': custom WebApplicationContext class [" +
                getContextClass().getName() + "] is not of type ConfigurableWebApplicationContext");
    }

    ConfigurableWebApplicationContext wac =
            (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(getContextClass());
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setNamespace(getNamespace());
    if (getContextConfigLocation() != null) {
        wac.setConfigLocations(
            StringUtils.tokenizeToStringArray(
                        getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
    }
    wac.addBeanFactoryPostProcessor(
            new BeanFactoryPostProcessor() {
                public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
                    beanFactory.addBeanPostProcessor(new ActionServletAwareProcessor(getActionServlet()));
                    beanFactory.ignoreDependencyType(ActionServlet.class);
                }
            }
    );

    wac.refresh();
    return wac;
}
项目:spring-component-framework    文件:ContextUtils.java   
/**
 * 继承上级上下文中的属性配置器
 *
 * @param inheriting  上级上下文
 * @param context 当前上下文
 */
public static void inheritParentProperties(ApplicationContext inheriting,
                                           GenericApplicationContext context) {
    if (!(inheriting instanceof AbstractApplicationContext)) return;
    List<BeanFactoryPostProcessor> processors =
            ((AbstractApplicationContext) inheriting).getBeanFactoryPostProcessors();
    for (BeanFactoryPostProcessor processor : processors) {
        if (processor instanceof PropertyResourceConfigurer)
            context.addBeanFactoryPostProcessor(processor);
    }
}
项目:class-guard    文件:AbstractApplicationContext.java   
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private void invokeBeanFactoryPostProcessors(
        Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

    for (BeanFactoryPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessBeanFactory(beanFactory);
    }
}
项目:class-guard    文件:ConfigurationClassProcessingTests.java   
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
    return new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
            BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
            bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
        }
    };
}
项目:class-guard    文件:ConfigurationClassAndBFPPTests.java   
@Bean
public BeanFactoryPostProcessor bfpp() {
    return new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            // no-op
        }
    };
}
项目:class-guard    文件:ConfigurationClassAndBFPPTests.java   
@Bean
public static final BeanFactoryPostProcessor bfpp() {
    return new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            // no-op
        }
    };
}
项目:class-guard    文件:ContextLoaderPlugIn.java   
/**
 * Instantiate the WebApplicationContext for the ActionServlet, either a default
 * XmlWebApplicationContext or a custom context class if set.
 * <p>This implementation expects custom contexts to implement ConfigurableWebApplicationContext.
 * Can be overridden in subclasses.
 * @throws org.springframework.beans.BeansException if the context couldn't be initialized
 * @see #setContextClass
 * @see org.springframework.web.context.support.XmlWebApplicationContext
 */
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
        throws BeansException {

    if (logger.isDebugEnabled()) {
        logger.debug("ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
                "', module '" + getModulePrefix() + "' will try to create custom WebApplicationContext " +
                "context of class '" + getContextClass().getName() + "', using parent context [" + parent + "]");
    }
    if (!ConfigurableWebApplicationContext.class.isAssignableFrom(getContextClass())) {
        throw new ApplicationContextException(
                "Fatal initialization error in ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
                "', module '" + getModulePrefix() + "': custom WebApplicationContext class [" +
                getContextClass().getName() + "] is not of type ConfigurableWebApplicationContext");
    }

    ConfigurableWebApplicationContext wac =
            (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(getContextClass());
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setNamespace(getNamespace());
    if (getContextConfigLocation() != null) {
        wac.setConfigLocations(
            StringUtils.tokenizeToStringArray(
                        getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
    }
    wac.addBeanFactoryPostProcessor(
            new BeanFactoryPostProcessor() {
                public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
                    beanFactory.addBeanPostProcessor(new ActionServletAwareProcessor(getActionServlet()));
                    beanFactory.ignoreDependencyType(ActionServlet.class);
                }
            }
    );

    wac.refresh();
    return wac;
}
项目:class-guard    文件:FactoryBeanTests.java   
@Test
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

    BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
    ppc.postProcessBeanFactory(factory);

    Beta beta = (Beta) factory.getBean("beta");
    Alpha alpha = (Alpha) factory.getBean("alpha");
    Gamma gamma = (Gamma) factory.getBean("gamma");
    assertSame(beta, alpha.getBeta());
    assertSame(gamma, beta.getGamma());
}
项目:sakai    文件:SakaiApplicationContext.java   
/**
 * Add bean-created post processors.
 * @param beanFactory
 */
public void invokePostProcessorCreators(ConfigurableListableBeanFactory beanFactory) {
    String[] postProcessorCreatorNames = beanFactory.getBeanNamesForType(BeanFactoryPostProcessorCreator.class, false, false);
    for (int i = 0; i < postProcessorCreatorNames.length; i++) {
        BeanFactoryPostProcessorCreator postProcessorCreator = (BeanFactoryPostProcessorCreator)beanFactory.getBean(postProcessorCreatorNames[i]);
        for (BeanFactoryPostProcessor beanFactoryPostProcessor : postProcessorCreator.getBeanFactoryPostProcessors()) {
            addBeanFactoryPostProcessor(beanFactoryPostProcessor);
        }
    }
}