Customize destruction callback for AutoCloseable beans
Previously, a Bean implementing `AutoCloseable` (or `Closeable`) was always destroyed regardless of its bean definition. In particular, the documented way of disabling the destruction callback via an empty String did not work. AutoCloseable beans are now treated pretty much as any other bean: we still use the presence of the interface to optimize the check of a destroy method and we only auto-discover the method name to invoke if the inferred mode is enabled. Issue: SPR-13022
This commit is contained in:
@@ -236,7 +236,7 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
}
|
||||
|
||||
String destroyMethodName = bean.getString("destroyMethod");
|
||||
if (StringUtils.hasText(destroyMethodName)) {
|
||||
if (destroyMethodName != null) {
|
||||
beanDef.setDestroyMethodName(destroyMethodName);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,8 +165,8 @@ class ScriptBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
||||
bd.setInitMethodName(beanDefinitionDefaults.getInitMethodName());
|
||||
}
|
||||
|
||||
String destroyMethod = element.getAttribute(DESTROY_METHOD_ATTRIBUTE);
|
||||
if (StringUtils.hasLength(destroyMethod)) {
|
||||
if (element.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) {
|
||||
String destroyMethod = element.getAttribute(DESTROY_METHOD_ATTRIBUTE);
|
||||
bd.setDestroyMethodName(destroyMethod);
|
||||
}
|
||||
else if (beanDefinitionDefaults.getDestroyMethodName() != null) {
|
||||
|
||||
@@ -505,7 +505,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
|
||||
Signature signature = new Signature(abd.getInitMethodName(), Type.VOID_TYPE, new Type[0]);
|
||||
maker.add(signature, new Type[0]);
|
||||
}
|
||||
if (abd.getDestroyMethodName() != null) {
|
||||
if (StringUtils.hasText(abd.getDestroyMethodName())) {
|
||||
Signature signature = new Signature(abd.getDestroyMethodName(), Type.VOID_TYPE, new Type[0]);
|
||||
maker.add(signature, new Type[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user