我有一个使用 Spring 3 的 Web 应用程序,其中 Controller 用 @Controller 注释。 Controller 的公共(public)方法使用@RequestMapping 注释。这工作得很好。
现在我想在调用 Controller 中的任何公共(public)方法之前进行检查。我已经使用切入点表达式创建了一个@Before 方面,该切入点表达式选择所有用@RequestMapping 注释的 Controller 方法。我已经使用
注册了方面<aop:aspectj-autoproxy>
<aop:include name="myAspect"/>
</aop:aspectj-autoproxy>
问题是,当我启动应用程序并请求某个 Controller 处理的某个 URL 时,我收到以下错误消息:
“没有处理程序 XXX 的适配器:您的处理程序是否实现了受支持的接口(interface),如 Controller?”
所以 Controller 不再工作了。有人知道如何解决这个问题吗?
最佳答案
肖恩·帕特里克·弗洛伊德是对的。还有另一种方法:从 Spring Proxy AOP 切换到 CGILib。
来自 Spring 引用:
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"/>
顺便说一句:我建议改用 AspectJ 或 Spring Proxy CGILib AOP。/
https://stackoverflow.com/questions/5578354/