Skip to content

Commit c2c6bb2

Browse files
sbrannenwilkinsona
andcommitted
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 spring-projects/spring-boot#40234 Closes gh-33811 Co-authored-by: Andy Wilkinson <[email protected]>
1 parent 40960fa commit c2c6bb2

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

Diff for: spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,8 @@ private Set<String> getExistingBeanNamesByType(ConfigurableListableBeanFactory b
286286
// Add matching FactoryBeans as well.
287287
for (String beanName : beanFactory.getBeanNamesForType(FactoryBean.class, true, false)) {
288288
beanName = BeanFactoryUtils.transformedBeanName(beanName);
289-
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
290-
Object attribute = beanDefinition.getAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE);
291-
if (resolvableType.equals(attribute) || type.equals(attribute)) {
289+
Class<?> producedType = beanFactory.getType(beanName, false);
290+
if (type.equals(producedType)) {
292291
beanNames.add(beanName);
293292
}
294293
}

Diff for: spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/integration/MockitoSpyBeanWithGenericsOnTestFieldForExistingGenericBeanProducedByFactoryBeanIntegrationTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.test.context.bean.override.mockito.integration;
1818

19-
import org.junit.jupiter.api.Disabled;
2019
import org.junit.jupiter.api.Test;
2120
import org.mockito.MockingDetails;
2221

@@ -48,7 +47,6 @@
4847
* @see MockitoSpyBeanWithGenericsOnTestFieldForExistingGenericBeanIntegrationTests
4948
*/
5049
@SpringJUnitConfig
51-
@Disabled("Disabled until https://github.com/spring-projects/spring-boot/issues/40234 is ported to Spring Framework")
5250
class MockitoSpyBeanWithGenericsOnTestFieldForExistingGenericBeanProducedByFactoryBeanIntegrationTests {
5351

5452
@MockitoSpyBean("exampleService")

0 commit comments

Comments
 (0)