[英]Aspectj with spring aop configuration xml
I'm working in an application which uses Spring, version 3.1.1, and now I need to add some aspects to it. 我正在使用使用Spring 3.1.1版的应用程序,现在需要在其中添加一些方面。 The aspects are written in aspectj language without annotations.
方面以Aspectj语言编写,没有注释。 I have read the spring docs chapter 8.8 , but I'm struggling to make it work.
我已经阅读了春季文档8.8章 ,但是我正在努力使其工作。
My spring configuration looks like: 我的弹簧配置如下:
<aop:aspectj-autoproxy proxy-target-class="true">
<aop:include name="loggerAspect"/>
</aop:aspectj-autoproxy>
<aop:config>
<!-- Beans -->
<aop:aspect id="loggerAspect" ref="loggerAspectBean">
<!-- Pointcuts -->
<aop:pointcut id="loggerPointcut" expression="execution(* foo.Bar.baz(..))"/>
<!-- Advice -->
<aop:around method="log" pointcut-ref="loggerPointcut"/>
</aop:aspect>
</aop:config>
<bean id="loggerAspectBean" class="foo.LoggerAspect"></bean>
In my pom, is a Maven project, i have spring-aop, aspectjrt and aspectjweaver as dependencies. 在我的pom中,是一个Maven项目,我将spring-aop,aspectjrt和Aspectjweaver作为依赖项。
My problem is that when launching the app I get a ClassNotFoundException
for foo.LoggerAspect
, which is comprehensible because foo.LoggerAspect
is an aspectj aspect, not a java class. 我的问题是,启动应用程序时,我得到
foo.LoggerAspect
的ClassNotFoundException
,这是可以理解的,因为foo.LoggerAspect
是foo.LoggerAspect
方面,而不是Java类。
So my question is: 所以我的问题是:
.aj
file? .aj
文件编写的.aj
方面? Annotations aren't possible here, aspects are a given and cannot modify them and need to preserve the configuration by XML. 这里是不可能的注释,方面是给定的,不能修改它们,需要通过XML保留配置。
Ok simple solution, just compile the aj
files with the ajc compiler and you get a class file (if you compile for LTW) and then the class is found. 好的简单解决方案,只需使用ajc编译器编译
aj
文件,您将获得一个类文件(如果您为LTW进行编译),然后找到该类。 And adding <context:load-time-weaver aspectj-weaving="on"/>
did the rest. 并添加
<context:load-time-weaver aspectj-weaving="on"/>
完成其余工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.