使用AspectJ的Spring AOP-加载时间编织的疑问 [英] Spring AOP with AspectJ - Load time weaving doubts

查看:157
本文介绍了使用AspectJ的Spring AOP-加载时间编织的疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读Spring AOP文档(

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 named spring-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并运行胖子.在这种情况下,您不需要@EnableLoadTimeWeavingspring-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆