ClassPathXmlApplicationContext的获得方式:ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext(“Beans.xml”);
重要的成员变量:
beanFactory: DefaultListableBeanFactory
beanFactoryPostProcessors: ArrayList
classLoader: sun.misc.Launcher$AppClassLoader@14dad5dc
configLocations: Beans.xml
- Logger: Jdk14Logger
如何判断ClassPathXmlApplicationContext容器里是否包含某bean?
使用方法containsBean:
delegate给getBeanFactory().containsBean方法:这个containsBean方法定义在AbstractApplicationContext里:而getBeanFactory的实现,位于AbstractRefreshableApplicationContext里:DefaultListableBeanFactory里有个成员变量beanDefinitionMap, 是一个ConcurrentHashMap:我在Beans.xml里定义的bean就存储在这个hashmap里,因此最后context.containsBean返回true: