Spring AOP是否编译编织时间或加载时间编织? [英] Does Spring AOP do compile time weaving or load time weaving?

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

问题描述

我开始使用Spring AOP进行项目,我对编织有点困惑。我知道Spring AOP依赖于AspectJweaver.jar,但是正如文档所说,这不是编织,而是它使用了这个jar中的一些类。

I am starting to use Spring AOP for a project and I am a little bit confused about weaving. I know that Spring AOP has a dependency on AspectJweaver.jar, but as the documentation says, this is not for the weaving, but just that it uses some of the classes from this jar.

但我的问题是,如果没有使用AspectJ进行编织,Spring AOP是否有自己的编织,是在加载时还是编译时执行?

But my question is, if it is not using AspectJ for weaving, does Spring AOP have its own weaving and is it performed at load time or compile time?

我的Spring配置XML文件的相关部分是:

The relevant part of my Spring Configuration XML file is:

<context:annotation-config />

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="get*" read-only="true" />
        <tx:method name="*" />
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="myaop" expression="execution(* my.package.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="myaop" />
</aop:config>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>


推荐答案

http://docs.spring.io/spring/docs/4.0.1.RELEASE/ spring-framework-reference / htmlsingle /#aop-introduction-defn

在8.1.1项目编织中,它说:

Under 8.1.1, item weaving, it says:


编织:将方面与其他应用程序类型或对象链接到
创建一个建议对象。这可以在编译时完成(例如,使用
AspectJ编译器),加载时间或运行时。 Spring AOP,
和其他纯Java AOP框架一样,在运行时执行编织。

Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime.

Spring不做同样的类型加载时编织为AspectJ,但适用于代理,如文档的另一部分所述:

Spring doesn't do the same type of load-time weaving as AspectJ, but works on proxies, as described in another part of the documentation:

http://docs.spring.io/spring/docs/4.0.1.RELEASE/ spring-framework-reference / htmlsingle /#aop-understanding-aop-proxies

编辑:刚刚看到你的评论,你的假设是正确的。该文档提供了一个相当完整的解释,说明它是如何工作的。 :)

Just saw your comment, you are correct in that assumption. The documentation gives a rather complete explanation of how it works exactly. :)

这篇关于Spring AOP是否编译编织时间或加载时间编织?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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