Reputation: 171
I have a web-app using Spring 3, where controllers are annotated with @Controller. The public methods of the controllers are annotated with @RequestMapping. This works perfectly fine.
Now I want to do a check before invoking any of the public methods in the controllers. I've created a @Before aspect using a Pointcut expression that selects all controller methods annotated with @RequestMapping. I've registered the aspect using
<aop:aspectj-autoproxy>
<aop:include name="myAspect"/>
</aop:aspectj-autoproxy>
The problem is that when I've started the application and do a request for some URL handled by one of my controllers, I get the following error-message:
"No adapter for handler XXX: Does your handler implement a supported interface like Controller?"
So the controllers don't work anymore. Does anyone have an idea on how to fix this?
Upvotes: 2
Views: 5545
Reputation: 120771
Sean Patrick Floyd is right. There is an other way: switching form Spring Proxy AOP to CGILib.
From the Spring Reference:
It is possible to force the use of CGLIB, in those (hopefully rare) cases where you need to advise a method that is not declared on an interface, or where you need to pass a proxied object to a method as a concrete type.
http://static.springsource.org/spring/docs/3.0.x/reference/aop.html#aop-autoproxy-force-CGLIB
To force the use of CGLIB proxies set the value of the proxy-target-class attribute of the
<aop:config>
element to true:<aop:config proxy-target-class="true">
To force CGLIB proxying when using the @AspectJ autoproxy support, set the 'proxy-target-class' attribute of the
<aop:aspectj-autoproxy>
element to true:<aop:aspectj-autoproxy proxy-target-class="true"/>
BTW: I recommend to use AspectJ instead or Spring Proxy CGILib AOP./
Upvotes: 4
Reputation: 298838
Note
When using controller interfaces (e.g. for AOP proxying), make sure to consistently put all your mapping annotations - such as@RequestMapping
and@SessionAttributes
- on the controller interface rather than on the implementation class.
Source: Spring Reference > Web MVC Framework > Implementing Controllers
Upvotes: 4