0

I use Spring aop and Aspectj at compile time. The project structure is as follows

parent-module
|---aop
|---service
|---web-app

aop related stuff including annotation interface and aspects are in project aop, aop annotations are used in project service, and services are used in web-app

aspectj compile time weaving is applied to both service and web-app, pom is like

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.8</version>
    <configuration>
        <weaveDependencies>
            <weaveDependency>
                <groupId>com.group</groupId>
                <artifactId>aop</artifactId>
            </weaveDependency>
        </weaveDependencies>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
            </aspectLibrary>
        </aspectLibraries>
        <complianceLevel>1.8</complianceLevel>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>UTF-8</encoding>
        <showWeaveInfo>true</showWeaveInfo>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

This way, it works perfectly.

but since I think aspects are woven into service at compile time, why can't I remove aspectj compiler from web-app, then

java.lang.NoSuchMethodError: aspectOf() error

occurs when the aspects are invoked.

Why this is happening? What can I put in web-app's pom to make service's aspect work? Do I have to let aspectj weave both service and web-app at compile time?

Laurel
  • 5,965
  • 14
  • 31
  • 57
HooYao
  • 554
  • 5
  • 19
  • Aspectj runtime needs to be on the classpath for anything aspectj related to run. You can remove the compiler, but the `aspectj-runtime.jar` must be on the classpath. – Nándor Előd Fekete Jun 08 '16 at 04:05
  • @NándorElődFekete thank you Nandor, I included aspectjrt in web-app, but it's not working for me. It looks compiling web-app with aspectj is the only choice, but im wondering WHY... – HooYao Jun 08 '16 at 08:09
  • Oh, okay. I think I misunderstood your question. Could you post the complete stack trace to the exception? Btw, is there any reson not to use the AspectJ compiler for the webapp as well? – Nándor Előd Fekete Jun 08 '16 at 13:10
  • Did you solve this problem? thanks. – meadlai Nov 12 '19 at 10:26

0 Answers0