Skip to content

Commit cd64e66

Browse files
committed
Prepare method overrides when bean class gets resolved
See gh-31826
1 parent 2acc7c6 commit cd64e66

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -496,15 +496,13 @@ protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable O
496496
if (resolvedClass != null && !mbd.hasBeanClass() && mbd.getBeanClassName() != null) {
497497
mbdToUse = new RootBeanDefinition(mbd);
498498
mbdToUse.setBeanClass(resolvedClass);
499-
}
500-
501-
// Prepare method overrides.
502-
try {
503-
mbdToUse.prepareMethodOverrides();
504-
}
505-
catch (BeanDefinitionValidationException ex) {
506-
throw new BeanDefinitionStoreException(mbdToUse.getResourceDescription(),
507-
beanName, "Validation of method overrides failed", ex);
499+
try {
500+
mbdToUse.prepareMethodOverrides();
501+
}
502+
catch (BeanDefinitionValidationException ex) {
503+
throw new BeanDefinitionStoreException(mbdToUse.getResourceDescription(),
504+
beanName, "Validation of method overrides failed", ex);
505+
}
508506
}
509507

510508
try {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,14 +1503,22 @@ protected Class<?> resolveBeanClass(RootBeanDefinition mbd, String beanName, Cla
15031503
if (mbd.hasBeanClass()) {
15041504
return mbd.getBeanClass();
15051505
}
1506-
return doResolveBeanClass(mbd, typesToMatch);
1506+
Class<?> beanClass = doResolveBeanClass(mbd, typesToMatch);
1507+
if (mbd.hasBeanClass()) {
1508+
mbd.prepareMethodOverrides();
1509+
}
1510+
return beanClass;
15071511
}
15081512
catch (ClassNotFoundException ex) {
15091513
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex);
15101514
}
15111515
catch (LinkageError err) {
15121516
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err);
15131517
}
1518+
catch (BeanDefinitionValidationException ex) {
1519+
throw new BeanDefinitionStoreException(mbd.getResourceDescription(),
1520+
beanName, "Validation of method overrides failed", ex);
1521+
}
15141522
}
15151523

15161524
@Nullable

0 commit comments

Comments
 (0)