是有什么样@ predestroy在春天作为温莎城堡 [英] is there something like @predestroy in the spring as in the castle windsor

查看:131
本文介绍了是有什么样@ predestroy在春天作为温莎城堡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何像 @ preDestroy 在春天的框架?

推荐答案

如果你定义一个实现了DisposableBean接口的bean Spring会调用

If you define a bean that implements the DisposableBean interface then Spring will call the

void destroy() throws Exception;

destrying bean的方法之前。

method before destrying the bean.

这是一种方式,另一种是当你的bean没有实现给定的接口。
在你的一个ConfigurationSupport类你的bean已经被定义为与该@Bean注释推进公众的方法。

That's one way, the other is when your bean doesn't have to implement the given interface. In one of yours ConfigurationSupport classes your bean has to be defined as as pulic method with the @Bean annotation.

   @Bean (destroyMethodName="yourDestroyMethod")
   public YourBean yourBean() {
      YourBean yourBean = new YourBean();

      return yourBean;
   }

方法yourDestroyMethod已在YourBean.class定义和Spring会破坏bean之前调用它。

The method "yourDestroyMethod" has to be defined in YourBean.class and then Spring will call it before destroying the bean.

有关更多信息请参阅Spring文档:<一href=\"http://static.springsource.org/spring/docs/3.0.x/reference/beans.html#beans-factory-lifecycle-disposablebean\">Destruction回调

For more info see the Spring documentation: Destruction callbacks

更新

第三条道路... 我甚至可以说是更好的方式将specifiy初始化方法和消灭法你的bean的......这样的:<一href=\"http://mkyong.com/spring/spring-init-method-and-destroy-method-example\">mkyong.com/spring/spring-init-method-and-destroy-method-example

The third way... I would even say the better way would be to specifiy "init-method" and "destroy-method" of your bean... like this: mkyong.com/spring/spring-init-method-and-destroy-method-example

这解决了这个问题OT第三方的依赖豆和解放了的code不必要的春天接口。

This solves the problem ot third-party dependency beans, and liberates the the code unnecessary Spring interfaces..

这篇关于是有什么样@ predestroy在春天作为温莎城堡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆