Package org.springframework.beans.factory.config

Examples of org.springframework.beans.factory.config.BeanFactoryPostProcessor


  /**
   * Invoke the given BeanFactoryPostProcessor beans.
   */
  private void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory, List postProcessors) {
    for (Iterator it = postProcessors.iterator(); it.hasNext();) {
      BeanFactoryPostProcessor postProcessor = (BeanFactoryPostProcessor) it.next();
      postProcessor.postProcessBeanFactory(beanFactory);
    }
  }
View Full Code Here


   * <p>Must be called before singleton instantiation.
   */
  protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) {
    // Invoke factory processors registered with the context instance.
    for (Iterator it = getBeanFactoryPostProcessors().iterator(); it.hasNext();) {
      BeanFactoryPostProcessor factoryProcessor = (BeanFactoryPostProcessor) it.next();
      factoryProcessor.postProcessBeanFactory(beanFactory);
    }

    // Do not initialize FactoryBeans here: We need to leave all regular beans
    // uninitialized to let the bean factory post-processors apply to them!
    String[] factoryProcessorNames =
        beanFactory.getBeanNamesForType(BeanFactoryPostProcessor.class, true, false);

    // Separate between BeanFactoryPostProcessors that implement the Ordered
    // interface and those that do not.
    List orderedFactoryProcessors = new ArrayList();
    List nonOrderedFactoryProcessorNames = new ArrayList();
    for (int i = 0; i < factoryProcessorNames.length; i++) {
      if (isTypeMatch(factoryProcessorNames[i], Ordered.class)) {
        orderedFactoryProcessors.add(beanFactory.getBean(factoryProcessorNames[i]));
      }
      else {
        nonOrderedFactoryProcessorNames.add(factoryProcessorNames[i]);
      }
    }

    // First, invoke the BeanFactoryPostProcessors that implement Ordered.
    Collections.sort(orderedFactoryProcessors, new OrderComparator());
    for (Iterator it = orderedFactoryProcessors.iterator(); it.hasNext();) {
      BeanFactoryPostProcessor factoryProcessor = (BeanFactoryPostProcessor) it.next();
      factoryProcessor.postProcessBeanFactory(beanFactory);
    }
    // Second, invoke all other BeanFactoryPostProcessors, one by one.
    for (Iterator it = nonOrderedFactoryProcessorNames.iterator(); it.hasNext();) {
      String factoryProcessorName = (String) it.next();
      ((BeanFactoryPostProcessor) getBean(factoryProcessorName)).postProcessBeanFactory(beanFactory);
View Full Code Here

      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);
          }
        }
View Full Code Here

    root = new XmlPortletApplicationContext();
    PortletContext portletContext = new MockPortletContext();
    PortletConfig portletConfig = new MockPortletConfig(portletContext);
    root.setPortletConfig(portletConfig);
    root.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/applicationContext.xml"});
    root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
      public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
          public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
            if(bean instanceof TestBean) {
              ((TestBean) bean).getFriends().add("myFriend");
View Full Code Here

            return;
        }

        Map parentPostProcessors = parent.getBeansOfType(BeanFactoryPostProcessor.class);
        for (Object o : parentPostProcessors.values()) {
            BeanFactoryPostProcessor postProcessor = (BeanFactoryPostProcessor) o;
            ((ConfigurableApplicationContext) springConfig.getUnrefreshedApplicationContext())
                .addBeanFactoryPostProcessor(postProcessor);
        }
    }
View Full Code Here

    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
       new String[] { "file:///" + explodedServiceUnitRoot.getAbsolutePath() + "/" + getXBeanFile() },
           false);
        List beanFactoryPostProcessors = getBeanFactoryPostProcessors(explodedServiceUnitRoot.getAbsolutePath());
        for (Iterator iter = beanFactoryPostProcessors.iterator(); iter.hasNext();) {
            BeanFactoryPostProcessor processor = (BeanFactoryPostProcessor) iter.next();
            context.addBeanFactoryPostProcessor(processor);
        }
        context.refresh();
    for (int i = 0; i < context.getBeanDefinitionNames().length; i++) {
      Object bean = context.getBean(context.getBeanDefinitionNames()[i]);
View Full Code Here

        String resolvedLocation = baseDir.toURI().resolve(location).getPath();
        String configLocation = "/" + resolvedLocation + ".xml";
        applicationContext = createXmlApplicationContext(configLocation);

        for (Iterator iter = beanFactoryPostProcessors.iterator(); iter.hasNext();) {
            BeanFactoryPostProcessor processor = (BeanFactoryPostProcessor) iter.next();
            applicationContext.addBeanFactoryPostProcessor(processor);
        }
        applicationContext.setDisplayName(location);

        ClassLoader classLoader = applicationContext.getClassLoader();
View Full Code Here

    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    beanFactory.registerBeanDefinition("factory", new RootBeanDefinition(LocalContainerEntityManagerFactoryBean.class));

    ConfigurableListableBeanFactory childFactory = new DefaultListableBeanFactory(beanFactory);

    BeanFactoryPostProcessor processor = new EntityManagerBeanDefinitionRegistrarPostProcessor();
    processor.postProcessBeanFactory(childFactory);

    assertThat(beanFactory.getBeanDefinitionCount(), is(2));
  }
View Full Code Here

    root = new XmlPortletApplicationContext();
    PortletContext portletContext = new MockPortletContext();
    PortletConfig portletConfig = new MockPortletConfig(portletContext);
    root.setPortletConfig(portletConfig);
    root.setConfigLocations(new String[] {"/org/springframework/web/portlet/context/WEB-INF/applicationContext.xml"});
    root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
      @Override
      public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
          @Override
          public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
View Full Code Here

  @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");
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.config.BeanFactoryPostProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.