Search code examples
javaspringmaven-2aopaspectj

Compile-time weaving configuration


I am trying to convert my load-time-woven aspectj to compile-time-woven.

So I removed <context:load-time-weaver/> from my spring config, and added an aspectj compiler to my pom.xml. But I don't know how to convert the info in META-INF/aop.xml.

I have something like this in there:

<!DOCTYPE aspectj PUBLIC
        "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
    <weaver>
        <!-- only weave classes in this package -->
    </weaver>
    <aspects>
        <!-- use only this aspect for weaving -->
        <concrete-aspect name="MyAspect_" extends="hu.myAspect">
        <pointcut name="pointcut" expression="execution(public * javax.persistence.EntityManager.*(..)) || execution(public * hu..*.create(..))"/>
        </concrete-aspect>
    </aspects>
</aspectj>

Solution

  • There is no exact equivalent to aop.xml in compile-time weaving, but you can configure the AspectJ maven plugin to include and exclude certain aspects like this

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.3</version>
        <configuration>
            <includes>
                <include>**/TransationAspect.java</include>
                <include>**/SecurityAspect.aj</include>
            </includes>
            <excludes>
                <exclude>**/logging/*.aj</exclude>
            </excludes>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>compile</goal>
                </goals>
            </execution>
        </executions>
    </plugin>