spring可以在在xml中配置 destroy-method 来指定销毁的方法
但是也也可以通过bean实现接口DisposableBean中的destroy方法来执行销毁的动作
请问这两种有什么区别?
而且是先执行destroy方法,后执行destroy-method执行的方法
为了弥补叙述的不清楚,我写了一个deamo方便理解问题描述
public class UserService implements InitializingBean,DisposableBean { public void destroy() throws Exception { System.out.println("1"); } public void teardown(){ System.out.println("2"); } }
It’s the difference in execution order.
One isencoding type, and the other isconfiguration type.
Coding means that you can directly include
init/destory
into the code during design. If you are very clear about your needs, you can directly use this method. The configuration is for external selection.Correct answer upstairs, haha