Spring AOP 与 AspectJ [英] Spring AOP vs AspectJ

查看:41
本文介绍了Spring AOP 与 AspectJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的印象是 Spring AOP 最适合用于特定于应用程序的任务,例如安全性、日志记录、事务等,因为它使用自定义 Java5 注释作为框架.然而,AspectJ 似乎更友好的设计模式明智.

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.

谁能强调在 Spring 应用程序中使用 Spring AOP 与 AspectJ 的各种优缺点?

Can anyone highlight the various pros and cons of using Spring AOP vs AspectJ in a Spring application?

推荐答案

Spring-AOP Pros

Spring-AOP Pros

  • 使用起来比 AspectJ 简单,因为您不必使用 LTW (加载时编织) 或 AspectJ 编译器.

  • It is simpler to use than AspectJ, since you don't have to use LTW (load-time weaving) or the AspectJ compiler.

它使用代理模式和装饰器模式

It uses the Proxy pattern and the Decorator pattern

Spring-AOP 的缺点

Spring-AOP Cons

  • 这是基于代理的 AOP,所以基本上你只能使用方法执行连接点.
  • 在同一类中调用另一个方法时不会应用方面.
  • 可能会有一些运行时开销.
  • Spring-AOP 无法向非 Spring 工厂创建的任何内容添加方面

AspectJ 优点

  • 这支持所有连接点.这意味着你可以做任何事情.
  • 运行时开销比 Spring AOP 少.

AspectJ 缺点

  • 小心点.检查您的方面是否仅按照您想要的方式进行了编织.
  • 您需要使用 AspectJ Compiler 进行额外的构建过程,或者必须设置 LTW(加载时编织)

这篇关于Spring AOP 与 AspectJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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