diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java index 1b3993476eb..5c735f16fb6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -278,8 +278,12 @@ public abstract class BeanUtils { targetMethod = method; numMethodsFoundWithCurrentMinimumArgs = 1; } - else { - if (targetMethod.getParameterTypes().length == numParams) { + else if (!method.isBridge() && targetMethod.getParameterTypes().length == numParams) { + if (targetMethod.isBridge()) { + // Prefer regular method over bridge... + targetMethod = method; + } + else { // Additional candidate with same length numMethodsFoundWithCurrentMinimumArgs++; } @@ -289,7 +293,7 @@ public abstract class BeanUtils { if (numMethodsFoundWithCurrentMinimumArgs > 1) { throw new IllegalArgumentException("Cannot resolve method '" + methodName + "' to a unique method. Attempted to resolve to overloaded method with " + - "the least number of parameters, but there were " + + "the least number of parameters but there were " + numMethodsFoundWithCurrentMinimumArgs + " candidates."); } return targetMethod; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java index 4cb8f2e12d9..d3a6c361c2e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -300,7 +300,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { } } catch (IllegalArgumentException ex) { - throw new BeanDefinitionValidationException("Couldn't find a unique destroy method on bean with name '" + + throw new BeanDefinitionValidationException("Could not find unique destroy method on bean with name '" + this.beanName + ": " + ex.getMessage()); } } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java index e3f877d3736..cbf2f37b929 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -2890,7 +2890,13 @@ public class DefaultListableBeanFactoryTests { } - public static class BeanWithDestroyMethod { + public static abstract class BaseClassWithDestroyMethod { + + public abstract BaseClassWithDestroyMethod close(); + } + + + public static class BeanWithDestroyMethod extends BaseClassWithDestroyMethod { private static int closeCount = 0; @@ -2900,8 +2906,10 @@ public class DefaultListableBeanFactoryTests { this.inner = inner; } - public void close() { + @Override + public BeanWithDestroyMethod close() { closeCount++; + return this; } }