Use BeanFactory to get type produced by a FactoryBean for Bean Overrides
Previously, we only looked at the OBJECT_TYPE_ATTRIBUTE on a FactoryBean's bean definition; however this does not work for situations where the information is provided by the definition's target type rather than the attribute. Rather than manually considering the target type in addition to the existing consideration of the attribute, we now ask the BeanFactory for the type that will be produced by the FactoryBean instead. See https://github.com/spring-projects/spring-boot/issues/40234 Closes gh-33811 Co-authored-by: Andy Wilkinson <andy.wilkinson@broadcom.com>
This commit is contained in:
@@ -286,9 +286,8 @@ class BeanOverrideBeanFactoryPostProcessor implements BeanFactoryPostProcessor,
|
||||
// Add matching FactoryBeans as well.
|
||||
for (String beanName : beanFactory.getBeanNamesForType(FactoryBean.class, true, false)) {
|
||||
beanName = BeanFactoryUtils.transformedBeanName(beanName);
|
||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
||||
Object attribute = beanDefinition.getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE);
|
||||
if (resolvableType.equals(attribute) || type.equals(attribute)) {
|
||||
Class<?> producedType = beanFactory.getType(beanName, false);
|
||||
if (type.equals(producedType)) {
|
||||
beanNames.add(beanName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user