我理解spring的生命周期回调init-method
当您需要根据 IoC 框架注入的依赖项进行初始化(而常规方法无法完成)时非常有用contructor
方法。但是在生命周期回调中进行清理有什么好处destroy-method
超过常规finalize
method?
finalize http://download.oracle.com/javase/6/docs/api/java/lang/Object.html#finalize()由垃圾收集器调用,因此是不保证被调用 https://stackoverflow.com/questions/2506488/java-finalize-method-call.
Springs destroy-method http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-lifecycle-default-init-destroy-methods or @PreDestroy http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-postconstruct-and-predestroy-annotations当 Spring 容器销毁 beans 时(例如,应用程序关闭时),容器会调用注释,允许您取消注册服务、终止线程或执行各种清理代码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)