AspectJ 有什么用? [英] What is AspectJ good for?
问题描述
首先让我注意,我使用 AspectJ 并且我喜欢它,但我还能用它做什么.
First let me note, that I use AspectJ and I like it, but what else can I do with it.
我知道 AspectJ 可以/正在用于日志记录.在某些情况下,它用于事务控制——主要与注释一起实现.AspectJ 也可用于使用(代码生成的)方法来增强类,就像 Spring Roo 那样.
I know AspectJ can be/is used for Logging. In some cases it is used for Transaction controlling – mostly implemented in conjunction with annotations. AspectJ can also be used to enhance classes with (code-generated) methods, like Spring Roo does.
但我相信 AspectJ 和 AOP 大体上可以用于:日志记录、事务控制和模拟部分类.
But I believe AspectJ and AOP in general, can be used for more than: logging, transaction controlling, and simulation partial classes.
那么 AspectJ 和 AOP 的其他有用用例是什么?
推荐答案
- 权限检查
- 中断耗时过长的操作
- 在单独的线程中运行操作,甚至在其他机器上的不同进程或事件的上下文中运行
- 监控
- 在调用前准备任何数据/环境并在调用后处理结果
- 打开/关闭资源
- 安全检查.
- 修复了您无法更改的 API 的错误或行为.例如,在某些条件下返回
false
但应该返回true
的布尔方法.您可以使用 AspectJ 解决此问题. - security check.
- fixes of incorrect or behavior of API that you cannot change. For example boolean method that returns
false
in some conditions but should returntrue
. You can fix this using AspectJ.
编辑
尽管我给出这个答案已经过去了很多年,但我还是决定添加以下内容以使答案更加完整.
Although many years passed since I gave this answer I decided to add the following to make the answer more complete.
这篇关于AspectJ 有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!