java - spring 中的 destroy-method 和 destroy方法的区别是什么?
迷茫
迷茫 2017-04-18 10:17:50
0
2
456

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"); } }
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all (2)
小葫芦

It’s the difference in execution order.
One isencoding type, and the other isconfiguration type.
Coding means that you can directly includeinit/destoryinto 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

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!