Add BeanFactory PostProcessor To XmlBeanFactory : Xml Bean Factory « Spring « Java Tutorial






File: context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

  <bean id="w" class="java.lang.String">
  </bean>

 
  <bean id="allBeansLister" class="AllBeansLister"/>

</beans>

File: Main.java

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

class Main {
  public static void main(String args[]) throws Exception {
    XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("context.xml"));
    factory.getBean("w");
    AllBeansLister lister = new AllBeansLister();
    lister.postProcessBeanFactory(factory);
  }
}
class AllBeansLister implements BeanFactoryPostProcessor {

  public void postProcessBeanFactory(ConfigurableListableBeanFactory factory)
      throws BeansException {
    
    System.out.println("The factory contains the followig beans:");
    String[] beanNames = factory.getBeanDefinitionNames();
    for (int i = 0; i < beanNames.length; ++i)
      System.out.println(beanNames[i]);
  }
}
  Download:  Spring-AddBeanFactoryPostProcessorToXmlBeanFactory.zip( 2,894 k)








28.6.Xml Bean Factory
28.6.1.Xml Bean Factory Demo
28.6.2.Static Factory
28.6.3.Compare Beans From Factory Bean
28.6.4.Create XmlBeanFactory from ClassPathResource
28.6.5.BeanFactory Aware
28.6.6.Non Static Factory
28.6.7.Hierarchical BeanFactory Demo
28.6.8.Add BeanFactory PostProcessor To XmlBeanFactory
28.6.9.Add addBeanPostProcessor To XmlBeanFactory