使用过程中出现的一个问题:
日志记录都已经弄好了,可以使用了,结果junit 测试加载 applicationContext.xml出现错误,
原因是:
将AOP配置时,将AOP类配置在applicationContext.xml中加载时无法加载
解决方案:
将AOP的所有配置写到SpringMVC-Context.xml文件中
eg:
<!-- 启动AspectJ自动代理 是自定义的注解在controller层生效 -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- AOP切面类 -->
<bean id="userOperationsLogging" class="cn.tit.ias.aop.UserOperationsLogging">
</bean>
建意:
对于AOP的所有配置都写到SpringMVC-Context.xml中。
<div class="article-copyright">
<span class="creativecommons">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">
</a>
<span>版权声明:本文为博主原创文章,遵循<a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank"> CC 4.0 BY-SA </a>版权协议,转载请附上原文出处链接和本声明。 </span>
<div class="article-source-link2222">
本文链接:<a href="https://blog.csdn.net/tianjun2012/article/details/47809739">https://blog.csdn.net/tianjun2012/article/details/47809739</a>
</div>
</span>
</div>
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-3019150162.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-3019150162.css">
<div class="htmledit_views" id="content_views">
AOP切面的一个简单配置,及说明
首先对入口文件,web.xml分析:
还有一点,我们可以查到,加载这连个配置文件的累分别是:spring(applicationContext),SpringMVC(webApplicationContext)(希望没记错,记错了自己对应修改)
第一步,要明确,我们是在SpringMVC上aop监测,那么所有的报扫描注入都在SpringMVC的配置文件中完成,不要再spring的配置文件中完成,不然在开启代理后,发现还是没有起到任何作用。(当然,aopalliance-1.0.jar,aspectjweaver-1.8.6.jar这两个jar包不可缺少)
第二步,在SpringMVC的配置文件中开启它的代理模式:<aop:aspectj-autoproxy expose-proxy="true"></aop:aspectj-autoproxy>
第三步,进行aop监测相关方法的类的编写
最后就是一个小技巧,就是先测pointcut表达式的具体到某一个具体函数,成功后,在用.*来代替,在测,知道成功完成为止!!!!!
希望对大家有帮住,也希望有大牛深入剖析其中的原理。有看到的同学请给我转个链接,谢谢。