Refine DisposableBeanAdapter method discovery for native
After this commit, DisposableBeanAdapter can find destruction related methods even when hints are just specified at interface level, which is typically the case when a bean is exposed via one of its interfaces. Closes gh-29545
This commit is contained in:
parent
3a36d51473
commit
c5f0f7bb11
|
|
@ -49,6 +49,7 @@ import org.springframework.util.StringUtils;
|
|||
* @author Costin Leau
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
* @author Sebastien Deleuze
|
||||
* @since 2.0
|
||||
* @see AbstractBeanFactory
|
||||
* @see org.springframework.beans.factory.DisposableBean
|
||||
|
|
@ -253,7 +254,18 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
|||
@Nullable
|
||||
private Method determineDestroyMethod(String name) {
|
||||
try {
|
||||
return findDestroyMethod(name);
|
||||
Class<?> beanClass = this.bean.getClass();
|
||||
Method destroyMethod = findDestroyMethod(beanClass, name);
|
||||
if (destroyMethod != null) {
|
||||
return destroyMethod;
|
||||
}
|
||||
for (Class<?> beanInterface : beanClass.getInterfaces()) {
|
||||
destroyMethod = findDestroyMethod(beanInterface, name);
|
||||
if (destroyMethod != null) {
|
||||
return destroyMethod;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
throw new BeanDefinitionValidationException("Could not find unique destroy method on bean with name '" +
|
||||
|
|
@ -262,10 +274,10 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private Method findDestroyMethod(String name) {
|
||||
private Method findDestroyMethod(Class<?> clazz, String name) {
|
||||
return (this.nonPublicAccessAllowed ?
|
||||
BeanUtils.findMethodWithMinimalParameters(this.bean.getClass(), name) :
|
||||
BeanUtils.findMethodWithMinimalParameters(this.bean.getClass().getMethods(), name));
|
||||
BeanUtils.findMethodWithMinimalParameters(clazz, name) :
|
||||
BeanUtils.findMethodWithMinimalParameters(clazz.getMethods(), name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue