Indicates a method that must be executed before a bean instance is destroyed when a module is stopped.
Unlike Beans with scope Bean.Strategy.SINGLETON, beans with scope
Bean.Strategy.PROTOTYPE might not be destroyed and therefore destroy
methods not invoked when they are created outside of a module and
dereferenced before the module is stopped. As a result you should generally
avoid defining destroy methods on beans with scope prototype. If you have
this kind of use case, consider creating prototype beans that implement
AutoCloseable, define the close() as destroy method,
make sure it can be invoked twice, and create new instances as follows to
make sure instance are properly destroyed:
try (MyPrototype instance = myModuleInstance.myPrototype()) {
...
}
- Since:
- 1.0
- Author:
- Jeremy Kuhn