Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspectJ CTW weaving works everywhere except for deployed WAR?

I've added AspectJ CTW to a project and things (appear) to work wonderfully. I can run the code in tests and it demonstrates that AspectJ is intercepting the appropriate methods. Once I package the code and deploy it to Tomcat in a WAR, it no longer works.

I've tried many different things but none of it seems to work. I'm using the Maven plugin in Maven 2 and I'm using AspectJ's annotations. All the feedback in the build says it's finding the methods and weaving.

Why does it stop working once it's deployed to Tomcat?

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.3</version>
            <configuration>
                <complianceLevel>1.6</complianceLevel>
                <source>1.6</source>
                <target>1.6</target>
                <showWeaveInfo>true</showWeaveInfo>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
like image 860
NickS Avatar asked Dec 06 '25 20:12

NickS


1 Answers

The fix for me was turning my call() pointcuts to execution().

As a first-time user of AspectJ, I hit my first "gotcha" that is actually listed directly in their FAQ. Code called via reflection won't trigger a call() pointcut.

http://www.eclipse.org/aspectj/doc/released/faq.php#q:reflectiveCalls

The problem was that, on the web application, the piece of interesting code was being called via reflection. In the tests, it worked fine because the class and method were being called directly. Hence, the tests worked fine but nothing worked once deployed.

The issue had nothing to do with Tomcat or deployment.

like image 85
NickS Avatar answered Dec 09 '25 08:12

NickS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!