-
Notifications
You must be signed in to change notification settings - Fork 356
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
SpringComponentProvider#bind() doesn't find Proxied beans #4096
Comments
I was trying to reproduce the issue per given description and everything works, could you please provide your version of a reproducer? |
I'm using quite outdated version 2.6 (jersey-spring3 artifact) but I have just tried to migrate to the newest 2.28 and the problem still appears (even from the repository it seems the mentioned class hasn't been changed since then). The problem is visible from the log message during the server startup:
I'm not sure if this is a harmless message or it if it has some effects. In my opinion, when using solely Spring container it should be fine unless you need integration with HK2 for which this binding is done. I hope it makes sense, if you need me to provide more detailed example in order to replicate this, let me know. Thanks! |
A reproducer would really come handy here |
@pjindracek Does it relate to #4080? |
Relates to this older issue. |
@jansupol The change in #4080 does not fix this issue. It assures that the beans will be searched throughout the Spring context hierarchy. The problem here is, that the search is done based on the class type of the resource, which is not the same because it is wrapped inside a java.lang.reflect.Proxy. A reproducer for this case:
Then if you put a breakpoint inside the org.glassfish.jersey.server.spring.SpringComponentProvider#bind method into the following condition:
you should see that there has been found zero beanNames for the defined resource |
@pjindracek I don't know why is the issue you are having. In the past (6 or 7 years ago) I was having a similar issue with Google Guice. The resources were injected by HK2, and all the other classes we injected by Guice. So I was not able to enhance classes with Guice aspects in the resources. Maybe you are having the same problem. But find here a working example with aspects in the resource, so you can take a look. You can run it in this way: This resource is supposed to return always "Response", but it is annotated with @MyAspect, and Spring should proxy the class to execute the code of MyAspectImpl. So that resource will always return "@MyAspect modified the response".
|
SpringComponentProvider#bind() method doesn't find proxied beans.
Preconditions:
SpringComponentProvider#bind() uses Spring's ListableBeanFactory#getBeanNamesForType(Class<?>) method to identify Spring beans of the REST resources in the Spring context by a class object of the Spring Component marked class. But if the resource classes are initialized as JDK AOP Proxies in the context (e.g Spring needs to use AOP to provide the cache functionality) then the JDK proxy is just a facade for the interface, not the actual implementing class.
In my opinion, the Spring Components should be found regardless whether they are Proxies - the result of the binding should be the same as if they are not.
The text was updated successfully, but these errors were encountered: