Javier Mr
Javier Mr

Reputation: 2200

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:

Annotations aren't possible here, aspects are a given and cannot modify them and need to preserve the configuration by XML.

Upvotes: 0

Views: 683

Answers (1)

Javier Mr
Javier Mr

Reputation: 2200

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.

Upvotes: 2

Related Questions