加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Spring AOP是否编译时编织或加载时间编织?

发布时间:2020-12-14 05:37:58 所属栏目:Java 来源:网络整理
导读:我开始使用 Spring AOP进行项目,我对编织有点困惑.我知道Spring AOP依赖于AspectJweaver.jar,但正如文档所说,这不是编织,而只是它使用了这个jar中的一些类. 但我的问题是,如果不使用AspectJ进行编织,Spring AOP是否有自己的编织,是在加载时还是编译时执行?
我开始使用 Spring AOP进行项目,我对编织有点困惑.我知道Spring AOP依赖于AspectJweaver.jar,但正如文档所说,这不是编织,而只是它使用了这个jar中的一些类.

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

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

<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项目编织下,它说:

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那样进行相同类型的加载时编织,但是在代理上工作,如文档的另一部分所述:

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读