Closed
Description
Michał Jaśtak opened SPR-12141 and commented
Suppose that I have class annotated with @Configuration
, in which I want to use Environment, injected by Spring Framework, something like this:
@Configuration
public class MyConfig {
@Inject
private Environment env;
...
}
When I declare bean using HttpInvokerProxyFactoryBean, and try to access injected environment to use one or the properties as for ex. service URL
@Bean
public FactoryBean someService() {
final HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean();
factory.setServiceInterface(SomeService.class);
factory.setServiceUrl(env.getRequiredProperty("service.uri"));
return factory;
}
I get NPEx because Spring Framework is trying to instantiate the factory before Environment is injected.
The problem doesn't exist, if I declare returned type as FactoryBean<SomeService>, but because of current signature of HttpInvokerProxyFactoryBean, I'm unable to use it directly (it implements FactoryBean<Object>).
Affects: 3.2.10, 4.0.6, 4.1 RC2
Issue Links:
- HttpInvokerProxyFactoryBean and co do not reliably expose correct type when declared via @Bean [SPR-11842] #16461 HttpInvokerProxyFactoryBean and co do not reliably expose correct type when declared via
@Bean
- StackOverflowError for advisor search against factory-bean reference to FactoryBean [SPR-14551] #19119 StackOverflowError for advisor search against factory-bean reference to FactoryBean
- Better error reporting for circular dependencies between JavaConfig classes [SPR-12317] #16922 Better error reporting for circular dependencies between JavaConfig classes