使用AspectJ的Spring AOP-加载时间编织的疑问 [英] Spring AOP with AspectJ - Load time weaving doubts
问题描述
Reading the Spring AOP
documentation (link), I'm having a hard time (maybe also because english is not my native language) understanding these paragraphs.
首先,我阅读
此外,在某些环境中,此支持可实现加载时间 编织时无需对应用程序服务器的服务器进行任何修改 添加所需的启动脚本
-javaagent:path/to/aspectjweaver.jar
或(如我们稍后将在 本节)-javaagent:path/to/org.springframework.instrument-{version}.jar
(以前称为spring-agent.jar
).
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 namedspring-agent.jar
).
还有
开发人员修改构成应用程序上下文的一个或多个文件 启用加载时编织
Developers modify one or more files that form the application context to enable load-time weaving
哪些文件? @Aspect
类和aop.xml
文件?
Which files? @Aspect
classes and aop.xml
files?
然后,当在同一子章节中描述示例时,他们说
Then, when describing an example in the same sub-chapter, they say
我们还有最后一件事要做.本节的引言确实说 可以在每个
ClassLoader
的基础上有选择地打开LTW 使用Spring,这是事实. 但是,对于本示例,我们使用 Java代理(Spring随附)以打开LTW.我们使用 以下命令运行前面显示的Main类:
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.
And they apply a Java Agent
to the JVM.
-javaagent:C:/projects/foo/lib/global/spring-instrument.jar
现在我有几个疑问.
Now I have a couple of doubts.
如果我@EnableLoadTimeWeaving
,我是否需要spring-instrument
Jar文件作为Java Agent
?
我想答案是肯定的,因为我们需要在加载class
文件之前将字节码添加到class
文件中.但确认将不胜感激.
If I @EnableLoadTimeWeaving
, do I need the spring-instrument
Jar file as Java Agent
?
I suppose the answer is yes, because we need to add bytecode to the class
file before loading it. But a confirmation would be much appreciated.
Jar的命名有点模糊,首先提到spring-agent.jar
,然后使用org.springframework.instrument-{version}.jar
,然后使用spring-instrument.jar
.
我们总是在谈论相同的Jar文件吗?
The Jar naming is a little ambiguos, first they mention spring-agent.jar
, then they use org.springframework.instrument-{version}.jar
, and then spring-instrument.jar
.
Are we always talking about the same Jar file?
推荐答案
我从另一个问题中看到,您问您正在使用Spring Boot并运行胖子.在这种情况下,您不需要@EnableLoadTimeWeaving
或spring-instrument
(以前称为spring-agent
).如果您不在没有控制代理路径的应用服务器中运行,请忽略它们.
I see from another question you asked that you are using Spring Boot and running a fat jar. In this case you don't need @EnableLoadTimeWeaving
or spring-instrument
(formerly known as spring-agent
). Just ignore them if you are not running in an appserver for which you don't control the agent path.
我为您打开了一个有关文档混乱的问题: https://github.com/spring-projects/spring-framework/issues/22429 .
I opened an issue for you about the confusion in the docs: https://github.com/spring-projects/spring-framework/issues/22429.
这篇关于使用AspectJ的Spring AOP-加载时间编织的疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!