I just tried to advice a Spring Controller using Spring AOP. For those of you that don't know it, Controllers can use annotations at type level for auto-detection, at method level for url auto-mapping and at method parameter level for forcing the use of certain parameters. For example:
Anyway, the Spring-specifics are not important.
The AOP proxy method has to be CGLib proxy(because the other option JDK proxy would not retain any annotation). And it works fine. The proxy retains the @Controller and @RequestMapping annotations so the controller is registered. What it doesn't work is the @RequestParam annotation. The proxied controller behaves as if the annotation it's not there.
This got me thinking. Can CGLib even transmit that to the proxy? If yes, then it must be a problem in the Spring AOP proxy creation/initialization. If not I'm doomed
AFAIK cglib proxies retain their annotations--Spring depends on annotations for other functionality as well, like injection and TX mgmt, so it strikes me as unlikely that this particular annotation would behave differently, you know?
posted 10 years ago
True, but most of those are processed before proxies are created for beans. Anyway, I know that GCLib retains annotations with ElementType=TYPE or METHOD. That's why @Controller and @RequestMapping works.
My only doubt was that annotations with ElementType=PARAMETER are retained (as far as I know RequestParam is the only one in Spring).