Spring AOP vs AspectJ [英] Spring AOP vs AspectJ
本文介绍了Spring AOP vs AspectJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以在Spring应用程序中突出显示使用Spring AOP和AspectJ的各种优缺点?
解决方案
Spring-AOP优点
- 使用比AspectJ更简单,因为您不必使用LTW(加载时编织)或AspectJ编译器。
- 当您使用基于Spring AOP的@Aspect注解时,可以更改为AspectJ AOP。
- 这使用Proxy模式和Decorator
模式
Spring-AOP缺点
- 是基于代理的AOP,所以基本上你只能使用方法执行切入点。
- 在同一个类中调用另一个方法时,不适用方面。
- Spring-AOP无法为Spring工厂不创建的任何内容添加一个方面
AspectJ优点
- 这支持所有切入点。这意味着你可以做任何事情。
- 运行时开销比Spring AOP少。
AspectJ Cons
- 小心。检查您的方面是否仅被编织成您想要编织的。
- 您需要使用AspectJ Compiler进行额外的构建过程,或者必须设置LTW(加载时编织)
I am under the impression that Spring AOP is best used for application specific tasks such as security, logging, transactions, etc. as it uses custom Java5 annotations as a framework. However, AspectJ seems to be more friendly design-patterns wise.
Can anyone highlight the various pros and cons of using Spring AOP vs AspectJ in a Spring application?
解决方案
Spring-AOP Pros
- It is simpler to use than AspectJ, since you don't have to use LTW (load-time weaving) or the AspectJ compiler.
- This can be change to AspectJ AOP when you use @Aspect annotation based Spring AOP.
- This use Proxy pattern and Decorator pattern
Spring-AOP Cons
- This is proxy-based AOP, so basically you can only use method-execution pointcut.
- Aspects aren't applied when calling another method within the same class.
- There can be a little runtime overhead.
- Spring-AOP cannot add an aspect to anything that is not created by the Spring factory
AspectJ Pros
- This supports all pointcuts. This means you can do anything.
- There is less runtime overhead than that of Spring AOP.
AspectJ Cons
- Be careful. Check if your aspects are weaved to only what you wanted to be weaved.
- You need extra build process with AspectJ Compiler or have to setup LTW (load-time weaving)
这篇关于Spring AOP vs AspectJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文