简体   繁体   English

如果可以单独使用Aspectj,在Spring配置中使用Aspectj有什么好处?

[英]What are benefits of using Aspectj in Spring config, if aspectj can be used alone

I looked at many Aspectj tutorials in web and most of them are: Aspectj config with Spring beans. 我看了很多Web上的Aspectj教程,其中大多数是:使用Spring bean的Aspectj配置。 Per my understanding, if I am using 据我了解,如果我正在使用

javaagent:./src/main/resources/aspectjweaver.jar and if I created aop.xml, aspectj weaving will work for all classes and objects (including those managed by Spring). javaagent:./src/main/resources/aspectjweaver.jar ,如果我创建了aop.xml,aspectj编织将适用于所有类和对象(包括由Spring管理的类和对象)。

Why do I need to enable weaving in Spring? 为什么我需要在春季启用编织? (like in this tutorial ). (如本教程中所示 )。 What's the benefit of doing: 这样做有什么好处:

<!-- this switches on the load-time weaving -->
    <context:load-time-weaver/>

AspectJ does not require Spring. AspectJ不需要Spring。 You can use aspectJ in your applications and benefit from the AOP paradigm. 您可以在应用程序中使用AspectJ并从AOP范例中受益。

Spring makes things a bit easier providing instrumentation to perform load-time-weaving easily, detecting Sun's GlassFish, Oracle's OC4J, Spring's VM agent and any ClassLoader supported by Spring's ReflectiveLoadTimeWeaver. Spring使事情变得更加容易,它提供了可以轻松执行加载时织入的工具,可以检测Sun的GlassFish,Oracle的OC4J,Spring的VM代理以及Spring的ReflectiveLoadTimeWeaver支持的任何ClassLoader。

For example, in case of Tomcat, Spring offers TomcatInstrumentableClassLoader which adds instrumentation to loaded classes without the need to use a VM-wide agent . 例如,对于Tomcat,Spring提供了TomcatInstrumentableClassLoader ,它无需使用VM范围的代理即可向已加载的类添加检测。

On the other hand, spring provides aspectJ integration which goes beyond the scope of your question. 另一方面,spring提供了aspectJ集成,这超出了您的问题范围。 But basically allows you to handle non managed spring beans in many ways (dependency injection, transactions...). 但基本上,您可以通过多种方式(依赖注入,事务...)来处理非托管的Spring bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM