Don't consider singleton instances when deducing bean class

Update `RegisteredBean` bean class detection to not consider
singletons. Prior to this commit, any beans that had been instantiated
could return the wrong class, especially if they were implemented using
a lambda.

See gh-28414
This commit is contained in:
Phillip Webb
2022-05-06 09:51:16 -07:00
parent 2b65f274dc
commit 7700570253
2 changed files with 11 additions and 16 deletions

View File

@@ -158,9 +158,6 @@ public final class RegisteredBean {
* @return the bean class
*/
public Class<?> getBeanClass() {
if (this.beanFactory.containsSingleton(getBeanName())) {
return this.beanFactory.getSingleton(getBeanName()).getClass();
}
return ClassUtils.getUserClass(getBeanType().toClass());
}
@@ -169,10 +166,6 @@ public final class RegisteredBean {
* @return the bean type
*/
public ResolvableType getBeanType() {
if (this.beanFactory.containsSingleton(getBeanName())) {
return ResolvableType
.forInstance(this.beanFactory.getSingleton(getBeanName()));
}
return getMergedBeanDefinition().getResolvableType();
}