Spring Boot. There is no way to get the time taken to load using aspectj function.
Can anyone please tell me why this aspect is not firing on spring boot? I am trying to tweak load times with aspectj so that I have personal methods.
Here is a link to the barebones project - https://github.com/satb/spring_aop_test_project.git
Start the "App" class with "-javaagent: path / to / spring -instrument-4.1.0.RELEASE.jar" (or whatever lib version on your machine) and run curl command
curl -i http://localhost:8080/test-app/motd
The MyAspect class has guidelines that should be followed when calling the private method MyService. But in this case, nothing happens.
When the application starts, I see the following message:
[AppClassLoader@58644d46] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified.
I tried the following suggestion from here to get it to work but it didn't help - Using @Autowired with AspectJ and Springboot
source to share
Ok, I took a quick look at the GitHub project. The POM is pretty strange, for example. it does not contain any dependency on spring tool. Also, you depend on aspectjweaver 1.8.2 but on aspectjweaver 1.5.4. You should really use the same version for both.
Anyway, I've experimented with various Java agents on the command line, and it seems that it's not enough to just use AspectJ weaver (result: exception) or just Spring Instrument (result: aspects don't work, just like you described). You need to use both parameters:
java -javaagent:path/to/aspectjweaver-1.8.2.jar -javaagent:path/to/spring-instrument-4.1.0.RELEASE.jar ...
This works for me with your code and gives a console on the console when using Curl as per your description:
[AppClassLoader@58644d46] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.1.6.RELEASE) 2014-09-08 13:09:54.489 INFO 1464 --- [ main] App : Starting App on Xander-PC with PID 1464 (C:\Users\Alexander\Documents\java-src\SO_AJ_SpringBootPrivilegedAspect\target\classes started by Alexander in C:\Users\Alexander\Documents\java-src\SO_AJ_SpringBootPrivilegedAspect) 2014-09-08 13:09:54.513 INFO 1464 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6771beb3: startup date [Mon Sep 08 13:09:54 CEST 2014]; root of context hierarchy (...) 2014-09-08 13:09:56.257 INFO 1464 --- [ main] o.s.c.w.DefaultContextLoadTimeWeaver : Found Spring JVM agent for instrumentation 2014-09-08 13:09:56.259 INFO 1464 --- [ main] o.s.c.w.DefaultContextLoadTimeWeaver : Found Spring JVM agent for instrumentation Aspect of called (...) 2014-09-08 13:09:56.779 INFO 1464 --- [ main] App : Started App in 2.531 seconds (JVM running for 3.067) 2014-09-08 13:09:59.115 INFO 1464 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2014-09-08 13:09:59.115 INFO 1464 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2014-09-08 13:09:59.122 INFO 1464 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 7 ms Aspect of called Advising getter
source to share
Try to declare InstrumentationLoadTimeWeaver bean instead of explicitly using -javaagent: /path/to/org.springframework.instrument- {version} .jar. According to the documentation
To use it, you have to start the VM with Spring Agent, providing the following JVM options:
-javaagent: /path/to/org.springframework.instrument- {version} .jar
Note that this requires a change to the VM startup script, which may prevent you from using this in application server environments (depending on your operations policies). In addition, the JDK agent will handle the entire virtual machine, which can be expensive.
I hope to do it better, I think.
@Bean
public InstrumentationLoadTimeWeaver loadTimeWeaver() throws Throwable {
InstrumentationLoadTimeWeaver loadTimeWeaver = new InstrumentationLoadTimeWeaver();
return loadTimeWeaver;
}
The same can be done in the xml config.
source to share