javaspringaopaspectjspring-aop

Spring Boot - Compile time weaving and Spring AOP/run time weaving (proxies) in same project


What does Spring Boot do in the event that there is code to use both Spring AOP with run time weaving/use of proxies and compile time weaving in the same project. For example, say you have an aspect that looks like this:

@Aspect
@Component
public class TestAspect {
  // ...
}

where the existence of @Component would imply that we are using Spring AOP and proxies, and you have this in your pom.xml

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>aspectj-maven-plugin</artifactId>
  <version>1.11</version>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>       <!-- use this goal to weave all your main classes -->
        <goal>test-compile</goal>  <!-- use this goal to weave all your test classes -->
      </goals>
    </execution>
  </executions>
</plugin>

which would imply we are using compile time weaving.

Which one takes precedence? Is compile time weaving used, or proxies?


Solution

  • Hm, why didn't you just try? Wouldn't that have been faster than asking? OK, here are my thoughts:

    Bottom line: You cannot mix Spring AOP and AspectJ LTW, but you should be able to use Spring AOP + AspectJ CTW. You just should have good reasons to do so and understand what you are doing.