用Spring编译/加载时间编织 [英] Compile/load time weaving with spring

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

问题描述

The docs explain that, the LTW has to enabled either through the use of <context:load-time-weaver/> xml instruction or the use of @EnableLoadTimeWeaving annotation. However, I have done neither, but I still see that aspects are woven correctly in my projects!

  1. 在这种情况下,我不认为它们是在编译时编织的(但是是吗?),所以一定要在加载时进行编织吗?
  2. 即使是这种情况,在加载期间如何自动选择编织方面?如果未按照文档所述使用上述方法之一打开各个方面,这些方面是否仍应保持编织?
  3. 我的类路径中有aspectj-weaver,但这还不足以选择这两种编织类型,对吗?

推荐答案

Spring AOP 不依赖于 AspectJ 字节码编织.它只是从AspectJ项目中借用了用于定义方面的注释.它是一个单独实现的框架,该框架使用运行时代理来实现各方面.如果您的应用程序上下文中有<aop:aspectj-autoproxy />,那么spring将使用代理来实现对容器中的bean定义的受支持方面.

Spring AOP does not rely on AspectJ byte code weaving. It just borrows the annotations used to define aspects from the AspectJ project. It is a separately implemented framework that uses run-time proxies to implement aspects. If you have <aop:aspectj-autoproxy /> in your application context then spring is using proxies to implement supported aspects defined on beans that are in the container.

代理只能实现实际的 AspectJ 系统的全部功能的子集,基本上是包装方法的建议.由于代理的性质,其具有以下局限性:

Proxies can only achieve a sub-set of the full capabilities of the actual AspectJ system, basically advice that wraps methods. Due to their nature proxies have following limitations:

  • 仅在外部呼叫上拦截((违反代理边界)
  • 仅对public位成员进行拦截(private/protected无法被拦截)
  • 不了解本地电话(或使用thissuper的电话)
  • interception on external calls only (while breaching proxy boundary)
  • interception on public members only (private/protected can't be intercepted)
  • unawareness to local calls (or calls with this or super)

例如,如果您希望能够建议字段,则需要启用

If you want to be able to advise fields for example, you would need to enable the use of Native AspectJ.

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

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