带有 SpringAOP 的 AspectJ 方面不起作用

Aspect of AspectJ with SpringAOP doesn't work

我知道同一个问题有很多问题,但我真的不明白问题出在哪里,因为我尝试从头开始学习很多流行的教程,但仍然没有用。

我请你在这里看看我的项目 link to github 并提出一些建议,因为我真的放弃了让它工作。

我用的是Eclipse Luna + Tomcat 7,其他的大家可以看一下github因为这里真的不方便全部都过去


已解决:实际上,我认为我需要更具体地说明我为解决这个难题所做的工作:@tmarwen 给了我一个很好的提示,告诉我可能出了什么问题,我测试并看到我的 dao-context.xml 根本不实例化 bean。因此,我将所有 bean 实例化和 <aop:aspectj-autoproxy />web.xml 文件一起移动到 WEB-INF 中单独的 config.xml 文件。之后一切都开始完美运行。

首先要注意的是,您在 web.xml 文件下的根应用程序配置文件路径中引入了错字:

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:coms/config/dao-context.xml</param-value>
</context-param>

虽然它应该如下所示 (coms 没有 s):

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:com/config/dao-context.xml</param-value>
</context-param>

另一个提示是上下文配置文件位置,我敢打赌它在构建时不会被解释为资源文件。

由于您使用 Maven 作为构建工具,您可能需要将文件位置更改为 src/main/resoures 目录(默认目录作为 Maven 的资源位置),因此项目根文件夹的整个路径为:

  • src/main/resoures/com/config/dao-context.xml