编程语言
首页 > 编程语言> > Spring Boot – 无法使用aspectj进行编织加载时间

Spring Boot – 无法使用aspectj进行编织加载时间

作者:互联网

任何人都可以告诉我为什么使用弹簧靴时方面不会触发?我正在尝试使用aspectj设置加载时间编织,以便我可以建议私有方法.

这是准系统项目的链接 – https://github.com/satb/spring_aop_test_project.git

使用“-javaagent:path / to / spring-instrument-4.1.0.RELEASE.jar”(或计算机上的某些其他版本的lib)运行“App”类并运行curl命令

curl -i http://localhost:8080/test-app/motd

MyAspect类有一个建议,应该在调用MyService的私有方法时执行.但在这种情况下,没有任何反应.

当应用程序启动时,我看到如下消息:

[AppClassLoader@58644d46] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified.

我尝试按照这里的建议让它工作,但这没有帮助 – Using @Autowired with AspectJ and Springboot

解决方法:

好的,我快速浏览了一下你的GitHub项目. POM非常奇怪,例如它不包含任何对弹簧乐器的依赖.此外,您依赖于aspectjweaver 1.8.2,但是依赖于aspectjrt 1.5.4.你应该真的使用相同的版本.

无论如何,我在命令行上尝试了不同的Java代理,似乎只使用AspectJ weaver(结果:异常)或仅使用Spring Instrument(结果:方面不起作用,就像你描述的那样)是不够的.你需要同时使用:

java -javaagent:path/to/aspectjweaver-1.8.2.jar -javaagent:path/to/spring-instrument-4.1.0.RELEASE.jar ...

这适用于我的代码,并根据您的描述在使用Curl时在控制台上产生以下内容:

[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's JVM agent for instrumentation
2014-09-08 13:09:56.259  INFO 1464 --- [           main] o.s.c.w.DefaultContextLoadTimeWeaver     : Found Spring's 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

标签:spring,aop,spring-boot-2,load-time-weaving
来源: https://codeday.me/bug/20190612/1224595.html