gpt4 book ai didi

java - Spring AOP 是编译时织入还是加载时织入?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:10:05 24 4
gpt4 key购买 nike

我开始在一个项目中使用 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

编辑:刚刚看到您的评论,您的假设是正确的。该文档对它的工作原理给出了相当完整的解释。 :)

关于java - Spring AOP 是编译时织入还是加载时织入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21549371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com