java - 在 @Controller 方法上使用 @Before 方面与 Spring 不起作用

我有一个使用 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/

相关文章:

xml - 在 vb net 中从 XML 中获取值

math - 需要给定排名和底池金额的奖品奖励功能

django - 区分 ModelAdmin 媒体以在 Django 中添加/更改页面

oracle - 将过程中的值传递给 Select 语句

drupal - 如果编辑或添加表单,如何在 drupal 节点表单中检测?

java - 在 Java 中,我可以使用单个方法作为其他方法的计时器吗?

sql - 为 SQL 中的每个重复项获取较小的索引

r - 文件太大无法在 R 中打开?

perl - 如何在 perl 中的 fork 之间共享简单标量(计数器变量)?

python - OOP Python 向基类添加一些属性?