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:
parent
40960fa85a
commit
c2c6bb25c6
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.test.context.bean.override.mockito.integration;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockingDetails;
|
||||
|
||||
|
@ -48,7 +47,6 @@ import static org.mockito.Mockito.mockingDetails;
|
|||
* @see MockitoSpyBeanWithGenericsOnTestFieldForExistingGenericBeanIntegrationTests
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
@Disabled("Disabled until https://github.com/spring-projects/spring-boot/issues/40234 is ported to Spring Framework")
|
||||
class MockitoSpyBeanWithGenericsOnTestFieldForExistingGenericBeanProducedByFactoryBeanIntegrationTests {
|
||||
|
||||
@MockitoSpyBean("exampleService")
|
||||
|
|
Loading…
Reference in New Issue