Spring AOP与AspectJ——加载时间编织疑惑

Spring AOP with AspectJ - Load time weaving doubts

阅读 Spring AOP 文档 (link),我很难理解这些段落(可能也是因为英语不是我的母语)。

首先,我阅读了

Further, in certain environments, this support enables load-time weaving without making any modifications to the application server’s launch script that is needed to add -javaagent:path/to/aspectjweaver.jar or (as we describe later in this section) -javaagent:path/to/org.springframework.instrument-{version}.jar (previously named spring-agent.jar).

Developers modify one or more files that form the application context to enable load-time weaving

哪些文件? @Aspect 类 和 aop.xml 个文件?


然后,在同一子章中描述示例时,他们说

We have one last thing to do. The introduction to this section did say that one could switch on LTW selectively on a per-ClassLoader basis with Spring, and this is true. However, for this example, we use a Java agent (supplied with Spring) to switch on the LTW. We use the following command to run the Main class shown earlier:

他们将 Java Agent 应用到 JVM。

-javaagent:C:/projects/foo/lib/global/spring-instrument.jar

现在我有几个疑问。

如果我 @EnableLoadTimeWeaving,我是否需要 spring-instrument Jar 文件作为 Java Agent
我想答案是肯定的,因为我们需要在加载它之前将字节码添加到 class 文件中。但如能确认,将不胜感激。

Jar的命名有点模棱两可,先是spring-agent.jar,然后是org.springframework.instrument-{version}.jar,然后是spring-instrument.jar.
我们总是在谈论同一个 Jar 文件吗?

我从另一个问题中看到您使用的是 Spring Boot 和 运行 fat jar。在这种情况下,您不需要 @EnableLoadTimeWeavingspring-instrument(以前称为 spring-agent)。如果您不在您无法控制代理路径的应用服务器中 运行,请忽略它们。

我就文档中的混淆向您提出了一个问题:https://github.com/spring-projects/spring-framework/issues/22429