Reverted enhanceFactoryBean revision in 4.1.x (making it 4.2 only)
Issue: SPR-12915 Issue: SPR-13095
This commit is contained in:
@@ -289,7 +289,7 @@ class ConfigurationClassEnhancer {
|
||||
}
|
||||
else {
|
||||
// It is a candidate FactoryBean - go ahead with enhancement
|
||||
return enhanceFactoryBean(factoryBean, beanFactory, beanName);
|
||||
return enhanceFactoryBean(factoryBean.getClass(), beanFactory, beanName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,11 +365,11 @@ class ConfigurationClassEnhancer {
|
||||
* instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing,
|
||||
* it will not be proxied. This too is aligned with the way XML configuration works.
|
||||
*/
|
||||
private Object enhanceFactoryBean(final Object factoryBean, final ConfigurableBeanFactory beanFactory,
|
||||
private Object enhanceFactoryBean(Class<?> fbClass, final ConfigurableBeanFactory beanFactory,
|
||||
final String beanName) throws InstantiationException, IllegalAccessException {
|
||||
|
||||
Enhancer enhancer = new Enhancer();
|
||||
enhancer.setSuperclass(factoryBean.getClass());
|
||||
enhancer.setSuperclass(fbClass);
|
||||
enhancer.setUseFactory(false);
|
||||
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
|
||||
enhancer.setCallback(new MethodInterceptor() {
|
||||
@@ -378,7 +378,7 @@ class ConfigurationClassEnhancer {
|
||||
if (method.getName().equals("getObject") && args.length == 0) {
|
||||
return beanFactory.getBean(beanName);
|
||||
}
|
||||
return proxy.invoke(factoryBean, args);
|
||||
return proxy.invokeSuper(obj, args);
|
||||
}
|
||||
});
|
||||
return enhancer.create();
|
||||
|
||||
@@ -82,15 +82,6 @@ public class ConfigurationWithFactoryBeanAndAutowiringTests {
|
||||
ctx.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withFactoryBeanCallingBean() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(AppConfig.class);
|
||||
ctx.register(FactoryBeanCallingConfig.class);
|
||||
ctx.refresh();
|
||||
assertEquals("true", ctx.getBean("myString"));
|
||||
}
|
||||
|
||||
|
||||
static class DummyBean {
|
||||
}
|
||||
@@ -246,23 +237,4 @@ public class ConfigurationWithFactoryBeanAndAutowiringTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class FactoryBeanCallingConfig {
|
||||
|
||||
@Autowired
|
||||
private DummyBean dummyBean;
|
||||
|
||||
@Bean
|
||||
public MyFactoryBean factoryBean() {
|
||||
Assert.notNull(dummyBean, "DummyBean was not injected.");
|
||||
return new MyFactoryBean();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public String myString() {
|
||||
return factoryBean().getString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user