Skip to content

@RequestMapping-based controllers do not work for JDK proxies with annotated interfaces [SPR-5084] #9757

@spring-projects-issues

Description

@spring-projects-issues

Bruno Navert opened SPR-5084 and commented

When using JDK proxies (proxy-target-class=false), it is not possible to use @RequestMapping to automatically define controllers.

This works very well if no proxying is involved. However, when AOP is used and a proxy of the controller is created (implementing the appropriate interface, where the interface has @RequestMapping at type and method level), then it fails.

The code in DefaultAnnotationHandlerMapping properly finds @RequestMapping at type level in the interface (since it uses AnnotationUtils.findAnnotation), but then it looks for method-level annotations in DefaultAnnotationHandlerMapping.determineUrlsForHandlerMethods()

This method only looks at the implementation class (the proxy), and finds no such annotation.

It should use the same kind of logic that AnnotationUtils does, and check the method declaration in the relevant interface(s) for any annotation there. Alternatively, perhaps declaring @RequestMapping as @Inheritable would suffice? Not sure. In any case, it should be simple to find the interfaces, get the right method, and check for annotations there.

The reason I prefer JDK proxies to CGLIB-based ones is because when we use CGLIB, it creates memory leaks when the application is reloaded in Tomcat, while JDK proxies don't have this problem.


Affects: 2.5.4

1 votes, 7 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions