标签:person bean efi pat ring path table ade actor
1、将上一篇的测试代码修改如下
public class SpringTest { public static void main(String[] args) { ClassPathResource resource = new ClassPathResource("com/example/spring/beans.xml"); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory); reader.loadBeanDefinitions(resource); Person person = (Person)factory.getBean("person"); System.out.println(person.say()); Person person2 = (Person)factory.getBean("person"); System.out.println(person == person2); } }
输出结果:
Hello,Tom true
说明person和person2是同一个对象
如果此时在beans.xml增加属性scope="prototype",
则输出结果为false
Hello,Tom false
标签:person bean efi pat ring path table ade actor
原文地址:https://www.cnblogs.com/linlf03/p/11182614.html