且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法从 Spring 运行 aspectj 示例,第 4 步

更新时间:2022-06-18 04:57:37

IMO @EnableAspectJAutoProxy 对于本机 AspectJ 方面没有意义.它仅适用于 Spring AOP 方面.所以你有两个选择:

IMO @EnableAspectJAutoProxy does not make sense for a native AspectJ aspect. It only works for Spring AOP aspects. So you have two options:

  • 要么通过 Ajc(AspectJ 编译器)将原生 AspectJ 方面直接编译到 Spring 应用程序中.在这种情况下,您不需要任何注释来运行方面,只需在运行时在类路径上aspectjrt.jar.
  • 或者您采用 Spring 手册(第 9.8 章)中描述的规范方式,并使用 LTW(加载时编织)进行原生 AspectJ 方面.这可以分别通过 @EnableLoadTimeWeaving 在您的配置中启用.见第 9.8.4 章,在 Spring 框架中使用 AspectJ 进行加载时编织.
  • Either you compile your native AspectJ aspect right into your Spring application via Ajc (AspectJ compiler). In this case you do not need any annotations to get the aspects running, only aspectjrt.jar on the classpath during runtime.
  • Or you go the canonical way described in the Spring manual (chapter 9.8) and use LTW (load-time weaving) for native AspectJ aspects. This can be enabled in your configuration via @EnableLoadTimeWeaving or <context:load-time-weaver/>, respectively. See chapter 9.8.4, Load-time weaving with AspectJ in the Spring Framework.