
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
7.3 抽象工厂模式在Spring源码中的应用
在Spring中,所有工厂都是BeanFactory的子类。通过对BeanFactory的实现,我们可以从Spring的容器访问Bean。根据不同的策略调用getBean()方法,从而获得具体对象。

BeanFactory的子类主要有ClassPathXmlApplicationContext、XmlWebApplicationContext、StaticWebApplicationContext、StaticPortletApplicationContext、GenericApplicationContext和Static ApplicationContext。在Spring中,DefaultListableBeanFactory实现了所有工厂的公共逻辑。