我开始在一个项目中使用 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 http://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/htmlsingle/#aop-introduction-defn
在 8.1.1 项编织下,它说:
编织:将方面与其他应用程序类型或对象链接起来
创建一个建议对象。这可以在编译时完成(使用
例如,AspectJ 编译器)、加载时或运行时。春季AOP,
与其他纯 Java AOP 框架一样,在运行时执行编织。
Spring 不执行与 AspectJ 相同类型的加载时编织,但适用于代理,如文档的另一部分所述:
http://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/htmlsingle/#aop-understanding-aop-proxies http://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/htmlsingle/#aop-understanding-aop-proxies
编辑:刚刚看到您的评论,您的假设是正确的。该文档对它的工作原理给出了相当完整的解释。 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)