0

I've a requirement to use load time weaving in AspectJ in a spring application, from what I can see in different sources is that you've to pass the javaagent argument to your JVM for enabling the load time weaving.

i.e.

-javaagent:path/to/spring-aop-aspectj-ltw/spring-instrument-4.2.5.RELEASE.jar
-javaagent:path/to/spring-aop-aspectj-ltw/aspectjweaver-1.8.8.jar

I'm wondering is there any alternative way to initialize this in Spring applications?

P.S I'm using Gradle to build the project

Sagar Verma
  • 25
  • 1
  • 4
  • Would you mind explaining what the problem is about adding those command line parameters? You have to specify project-specific parameters all the time, e.g. class path (even though you might not notice because Gradle or Maven or your IDE do it for you, certain system properties in order to enable specific options and so forth. Just configure your build tool correctly and it will do it automatically for you. – kriegaex May 27 '20 at 08:45
  • This would required changes in deployment script in all the application that we've running in production. I'll explain my problem statement first, I've a requirement to create a fat JAR to do certain task, this also requires certain aspects to be invoked in case an object (which is not managed by Spring) is called. If a different application use this JAR, they'd first need to make changes in deployment scripts and would increase the integration process. – Sagar Verma May 27 '20 at 11:57
  • So making changes in configurations of all applications using your JAR is acceptable, just not changes in deployment scripts. Am I understanding you correctly? – kriegaex May 27 '20 at 14:49

2 Answers2

1

Use the following on a @Configuration annotated class.

@EnableLoadTimeWeaving(aspectjWeaving=ENABLED)
zlaval
  • 1,941
  • 1
  • 10
  • 11
  • I'm afraid but this wouldn't enable the load time weaving, I've already tried that but so far the aspects are not getting invoked – Sagar Verma May 27 '20 at 12:00
1

I guess no. You need the agents to actually facilitate the weaving before any of your application classes are loaded since they have to be rewritten. I think the @EnableLoadtimeWeaving config is just to tell CGLIB not to create proxy classes for your annotated code, because it's not necessary any more. But I'm not 100% sure on that last part tbh; it might as well tell the agents to actually weave the code, when they find it during classpath scanning.

And don't forget to configure your aop.xml in the META-INF directory!

godsim
  • 181
  • 1
  • 9