Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspectJ LTW of all applications deployed to a single JVM

I have bundled my aspectJ aspects into a single War (aspectsWar.war) file and deployed it to an application server with existing running applications and used LTW weaving with a javaagent on tomcat server.

I can see the aspect intercepting calls on the aspectsWar.war but not on the other applications running on the same jvm.

Is there a way to have my aspectj aspect to recognize and weave all the other running applications (preferably without having to modify the individual war files), probably through some custom classloading changes to app server...

Note: this is using aspectJ by itself without any Spring related integration.

Please advice.

like image 296
Sammy Avatar asked Nov 02 '22 21:11

Sammy


1 Answers

The restriction of load time weaving to specific class loaders is a feature provided by spring. As the documentation describes:

The value-add that the Spring Framework brings to AspectJ LTW is in enabling much finer-grained control over the weaving process. 'Vanilla' AspectJ LTW is effected using a Java (5+) agent, which is switched on by specifying a VM argument when starting up a JVM. It is thus a JVM-wide setting, which may be fine in some situations, but often is a little too coarse. Spring-enabled LTW enables you to switch on LTW on a per-ClassLoader basis, which obviously is more fine-grained and which can make more sense in a 'single-JVM-multiple-application' environment (such as is found in a typical application server environment).

Sorry for the long quote, but it's basically the answer for your question. Use the agent provided by AspectJ instead of the Spring load time weaving configuration in case you want to apply the aspects JVM wide.

like image 95
zagyi Avatar answered Nov 11 '22 16:11

zagyi