简体   繁体   中英

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. The aspects are written in aspectj language without annotations. I have read the spring docs chapter 8.8 , but I'm struggling to make it work.

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.

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.

So my question is:

  • How should I configure Spring so it uses aspectj aspects written in a .aj file?

Annotations aren't possible here, aspects are a given and cannot modify them and need to preserve the configuration by 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. And adding <context:load-time-weaver aspectj-weaving="on"/> did the rest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM