Skip to content

Commit

Permalink
Refine DisposableBeanAdapter method discovery for native
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sdeleuze committed Mar 30, 2023
1 parent 3a36d51 commit c5f0f7b
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* @author Costin Leau
* @author Stephane Nicoll
* @author Sam Brannen
* @author Sebastien Deleuze
* @since 2.0
* @see AbstractBeanFactory
* @see org.springframework.beans.factory.DisposableBean
Expand Down Expand Up @@ -253,7 +254,18 @@ else if (this.destroyMethodNames != null) {
@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 '" +
Expand All @@ -262,10 +274,10 @@ private Method determineDestroyMethod(String name) {
}

@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));
}

/**
Expand Down

0 comments on commit c5f0f7b

Please sign in to comment.