-
Notifications
You must be signed in to change notification settings - Fork 38.5k
HttpInvokerProxyFactoryBean and co do not reliably expose correct type when declared via @Bean [SPR-11842] #16461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Stéphane Nicoll commented The demo sample is available on the spring-framework-issues project |
Stéphane Nicoll commented Jürgen, I am assigning this one to 4.1 since our internal testing shows that there is indeed something we might do on our side. Pierre, it is recommended not to use such Of course, we could invoke the bean definition and actually create the bean to figure out the exact type but this may lead to beans being initialized too early in the application lifecycle. Either way, keep in mind that it's always best to define the runtime type of your bean as soon as possible. The following code snippet is an example of what I mean: @Bean
public MyService myService() {
HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean();
factory.setServiceUrl("/svc/dummy");
factory.setServiceInterface(MyService.class);
return (MyService) factory.getObject();
} |
Pierre Maréchal commented Hi Stéphane, That's exactly what I tried at first. But your code snippet would return a null because the FactoryBean has not yet been initialized fully. This would work:
though I find manually calling afterPropertiesSet() not very elegant. |
Stéphane Nicoll commented Oh, right sorry. Well, the XML declaration, is an XML declaration, right? We can just read the model that you have defined using XML without creating the |
Pierre Maréchal commented OK thanks for the clarification. So I guess that for the moment, the safest is to declare it this way:
Or is there a better way? |
Stéphane Nicoll commented I wouldn't consider this "safe" but I see what you mean. You're still exposing your service twice and MyService is now exposed as "myServiceFactoryBean" as well. Hopefully, the context is smart enough to relalize that this is the same instance so autowiring by type would still work. But If we improve our support in the future, this would probably cause a problem as we have now two different beans exposing the same type. Juergen Hoeller, thoughts? |
Juergen Hoeller commented Let's reposition this issue towards the specific FactoryBeans at hand here: We generally can't do much about type resolution for That said, we should at least have a better recommendation for how to set up HTTP invoker proxies (and other remoting proxies) in an Juergen |
Juergen Hoeller commented Taking a step from my previous comment... There is away to set up remoting proxies programmatically: via a ProxyFactory.getProxy call with an HttpInvokerClientInterceptor argument. We could make that combination more straightforward through a combined HttpInvokerProxyFactory builder class but it won't get significantly more convenient than that, so it might not be worth it individually. A framework-wide approach for a new proxy builder API style would be more compelling but we cannot take it that far at this point. In fact, there is a minor twist in the core container that significantly eases things: At the moment, for Note that an So in summary, this seems to be an isolated change with good rewards for Hope that helps, Juergen |
Pierre Maréchal opened SPR-11842 and commented
Using
@Bean
to declare my HttpInvokerProxyFactoryBean and@Autowire
to inject it, Spring does not seem to resolve that my bean depends on the factory bean.I've attached a sample project displaying the behaviour.
Simply run "mvn test"
un-commenting the
@DependsOn
in MyBean works around the issue though.Affects: 4.0.5
Attachments:
Issue Links:
@Bean
method leads to early call (pre injection)Referenced from: commits ae66e45, 85b2c7d
The text was updated successfully, but these errors were encountered: