AspectJ 有什么用? [英] What is AspectJ good for?

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

问题描述

首先让我注意,我使用 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 的其他有用用例是什么?

推荐答案

  • 权限检查
  • 中断耗时过长的操作
  • 在单独的线程中运行操作,甚至在其他机器上的不同进程或事件的上下文中运行
  • 监控
  • 在调用前准备任何数据/环境并在调用后处理结果
  • 打开/关闭资源
  • 编辑

    尽管我给出这个答案已经过去了很多年,但我还是决定添加以下内容以使答案更加完整.

    Although many years passed since I gave this answer I decided to add the following to make the answer more complete.

    • 安全检查.
    • 修复了您无法更改的 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 return true. You can fix this using AspectJ.

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

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