优艾设计网

spring 中的 destroy-method 和 destroy方法的区别是什么??

spring可以在在xml中配置 destroy-method 来指定销毁的方法
但是也也可以通过bean实现接口DisposableBean中的destroy方法来执行销毁的动作

请问这两种有什么区别?
而且是先执行destroy方法,后执行destroy-method执行的方法

为了弥补叙述的不清楚,我写了一个deamo方便理解问题描述

<bean id="userService" class="cn.demo3.UserService" init-method="init" destroy-method="teardown"> <property优艾设计网_设计客 name="info" value="凤姐"/> </bean>

public class UserService implements InitializingBean,DisposableBean { public void destroy() throws Exception { System.out.println("1"); } public void teardown(){ System.out.println("2"); } }


0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜