Reverted enhanceFactoryBean revision in 4.1.x (making it 4.2 only)

Issue: SPR-12915
Issue: SPR-13095
This commit is contained in:
Juergen Hoeller
2015-06-11 17:53:26 +02:00
parent 3227007816
commit 063a720ac0
2 changed files with 4 additions and 32 deletions

View File

@@ -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();

View File

@@ -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();
}
}
}