Spring学习之从BeanFactory接口开始--Bean的作用域
先看一下BeanFactory接口的三个子接口:
?
?
?
?
?
?
?
?
?
还是很清楚的
?
ListableBeanFactory:提供访问容器中bean基本信息的方法AutowireCapableBeanFactory:定义了将容器中的bean按某种方式进行自动装配的方法HierarchicalBeanFactory:提供了访问父容器的方法,这样就使得spring具有父子级联的IOC容器看一下BeanFactory定义的方法<bean id="singletonBean" name="code"> public static void main(String[] args) { Resource res = new ClassPathResource("javamxj/spring/basic/singleton/bean.xml"); BeanFactory factory = new XmlBeanFactory(res); HelloBean h1 = (HelloBean) factory.getBean("singletonBean"); h1.sayHello(); HelloBean h2 = (HelloBean) factory.getBean("singletonBean"); h2.sayHello(); System.out.println("h1==h2: " + (h1==h2)); System.out.println(""); HelloBean h3 = (HelloBean) factory.getBean("prototypeBean"); h3.sayHello(); HelloBean h4 = (HelloBean) factory.getBean("prototypeBean"); h4.sayHello(); System.out.println("h3==h4: " + (h3==h4)); }}
?运行结果为:
?
Hello! 这是singletonBean!