@Scope annotation for changing scope
他们的作用就和在bean标签中使用scope属性实现的功能是一样的
@Scope
作用:用于指定bean的作用范围
属性:
value:指定范围的取值。常用取值:singleton prototype(默认单例
default singleton
multiple cases
Related to the life cycle (understanding) @PreDestroy@PostConstruct
@PreDestroy
作用:用于指定销毁方法
@PostConstruct
作用:用于指定初始化方法
他们的作用就和在bean标签中使用init-method和destroy-method的作用一样
Add two methods to the business layer implementation class.
If you want to see the execution method of destroy, you should pay attention.
You can’t write it like this. You can only use the parent’s method without close.
It should be changed to
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
Note that it is not responsible to destroy spring with multiple instances and multiple instances here.