diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index 279f96ef59a8..8279434b86dd 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -496,15 +496,13 @@ protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable O if (resolvedClass != null && !mbd.hasBeanClass() && mbd.getBeanClassName() != null) { mbdToUse = new RootBeanDefinition(mbd); mbdToUse.setBeanClass(resolvedClass); - } - - // Prepare method overrides. - try { - mbdToUse.prepareMethodOverrides(); - } - catch (BeanDefinitionValidationException ex) { - throw new BeanDefinitionStoreException(mbdToUse.getResourceDescription(), - beanName, "Validation of method overrides failed", ex); + try { + mbdToUse.prepareMethodOverrides(); + } + catch (BeanDefinitionValidationException ex) { + throw new BeanDefinitionStoreException(mbdToUse.getResourceDescription(), + beanName, "Validation of method overrides failed", ex); + } } try { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 1e283092c502..8f2e431b09e9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -1503,7 +1503,11 @@ protected Class resolveBeanClass(RootBeanDefinition mbd, String beanName, Cla if (mbd.hasBeanClass()) { return mbd.getBeanClass(); } - return doResolveBeanClass(mbd, typesToMatch); + Class beanClass = doResolveBeanClass(mbd, typesToMatch); + if (mbd.hasBeanClass()) { + mbd.prepareMethodOverrides(); + } + return beanClass; } catch (ClassNotFoundException ex) { throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); @@ -1511,6 +1515,10 @@ protected Class resolveBeanClass(RootBeanDefinition mbd, String beanName, Cla catch (LinkageError err) { throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err); } + catch (BeanDefinitionValidationException ex) { + throw new BeanDefinitionStoreException(mbd.getResourceDescription(), + beanName, "Validation of method overrides failed", ex); + } } @Nullable