Skip to content

Commit 76bc9cf

Browse files
jhoellersbrannen
authored andcommitted
Prepare method overrides when bean class gets resolved
See gh-31826 See gh-31828 (cherry picked from commit cd64e66)
1 parent db52c77 commit 76bc9cf

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,13 @@ protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable O
493493
if (resolvedClass != null && !mbd.hasBeanClass() && mbd.getBeanClassName() != null) {
494494
mbdToUse = new RootBeanDefinition(mbd);
495495
mbdToUse.setBeanClass(resolvedClass);
496-
}
497-
498-
// Prepare method overrides.
499-
try {
500-
mbdToUse.prepareMethodOverrides();
501-
}
502-
catch (BeanDefinitionValidationException ex) {
503-
throw new BeanDefinitionStoreException(mbdToUse.getResourceDescription(),
504-
beanName, "Validation of method overrides failed", ex);
496+
try {
497+
mbdToUse.prepareMethodOverrides();
498+
}
499+
catch (BeanDefinitionValidationException ex) {
500+
throw new BeanDefinitionStoreException(mbdToUse.getResourceDescription(),
501+
beanName, "Validation of method overrides failed", ex);
502+
}
505503
}
506504

507505
try {

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1497,14 +1497,22 @@ protected Class<?> resolveBeanClass(RootBeanDefinition mbd, String beanName, Cla
14971497
if (mbd.hasBeanClass()) {
14981498
return mbd.getBeanClass();
14991499
}
1500-
return doResolveBeanClass(mbd, typesToMatch);
1500+
Class<?> beanClass = doResolveBeanClass(mbd, typesToMatch);
1501+
if (mbd.hasBeanClass()) {
1502+
mbd.prepareMethodOverrides();
1503+
}
1504+
return beanClass;
15011505
}
15021506
catch (ClassNotFoundException ex) {
15031507
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex);
15041508
}
15051509
catch (LinkageError err) {
15061510
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err);
15071511
}
1512+
catch (BeanDefinitionValidationException ex) {
1513+
throw new BeanDefinitionStoreException(mbd.getResourceDescription(),
1514+
beanName, "Validation of method overrides failed", ex);
1515+
}
15081516
}
15091517

15101518
@Nullable

0 commit comments

Comments
 (0)