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]);
}
}
|