測試方法
ApplicationContext ctx = new ClassPathXmlApplicationContext("hhh.xml");
Persons pp = (Persons) ctx.getBean("huan");
Persons pps = (Persons) ctx.getBean("huan");
System.out.println(pp == pps)
值
- singleton :容器初始化時創建實例,在整個容器證明週期中只創建一次 也是默認值
<bean id="huan" autowire="byName" class="cn.nokia.pojo.Persons" p:age="23" p:name="erhuan" depends-on="car"
></bean>
結果 true
- prototype : 原型的,容器初始化的時候不創建bean實例,每次請求的時候創建一個bean,並返回。
<bean id="huan" autowire="byName" class="cn.nokia.pojo.Persons" p:age="23" p:name="erhuan" depends-on="car"
scope="prototype"></bean>
結果 false