Skip to content

Commit 063a720

Browse files
committed
Reverted enhanceFactoryBean revision in 4.1.x (making it 4.2 only)
Issue: SPR-12915 Issue: SPR-13095
1 parent 3227007 commit 063a720

File tree

2 files changed

+4
-32
lines changed

2 files changed

+4
-32
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object
289289
}
290290
else {
291291
// It is a candidate FactoryBean - go ahead with enhancement
292-
return enhanceFactoryBean(factoryBean, beanFactory, beanName);
292+
return enhanceFactoryBean(factoryBean.getClass(), beanFactory, beanName);
293293
}
294294
}
295295

@@ -365,11 +365,11 @@ private boolean isCurrentlyInvokedFactoryMethod(Method method) {
365365
* instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing,
366366
* it will not be proxied. This too is aligned with the way XML configuration works.
367367
*/
368-
private Object enhanceFactoryBean(final Object factoryBean, final ConfigurableBeanFactory beanFactory,
368+
private Object enhanceFactoryBean(Class<?> fbClass, final ConfigurableBeanFactory beanFactory,
369369
final String beanName) throws InstantiationException, IllegalAccessException {
370370

371371
Enhancer enhancer = new Enhancer();
372-
enhancer.setSuperclass(factoryBean.getClass());
372+
enhancer.setSuperclass(fbClass);
373373
enhancer.setUseFactory(false);
374374
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
375375
enhancer.setCallback(new MethodInterceptor() {
@@ -378,7 +378,7 @@ public Object intercept(Object obj, Method method, Object[] args, MethodProxy pr
378378
if (method.getName().equals("getObject") && args.length == 0) {
379379
return beanFactory.getBean(beanName);
380380
}
381-
return proxy.invoke(factoryBean, args);
381+
return proxy.invokeSuper(obj, args);
382382
}
383383
});
384384
return enhancer.create();

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationWithFactoryBeanAndAutowiringTests.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@ public void withWildcardParameterizedFactoryBeanInterfaceAsReturnType() {
8282
ctx.refresh();
8383
}
8484

85-
@Test
86-
public void withFactoryBeanCallingBean() {
87-
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
88-
ctx.register(AppConfig.class);
89-
ctx.register(FactoryBeanCallingConfig.class);
90-
ctx.refresh();
91-
assertEquals("true", ctx.getBean("myString"));
92-
}
93-
9485

9586
static class DummyBean {
9687
}
@@ -246,23 +237,4 @@ public FactoryBean<?> factoryBean() {
246237
}
247238
}
248239

249-
250-
@Configuration
251-
static class FactoryBeanCallingConfig {
252-
253-
@Autowired
254-
private DummyBean dummyBean;
255-
256-
@Bean
257-
public MyFactoryBean factoryBean() {
258-
Assert.notNull(dummyBean, "DummyBean was not injected.");
259-
return new MyFactoryBean();
260-
}
261-
262-
@Bean
263-
public String myString() {
264-
return factoryBean().getString();
265-
}
266-
}
267-
268240
}

0 commit comments

Comments
 (0)