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

查看:797
本文介绍了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的其他有用用例是什么?

推荐答案


  • 权限检查

  • 需要花费太长时间的中断操作

  • 单独执行操作线程或甚至在其他机器上的不同进程或事件的上下文中

  • 监控

  • 在呼叫之前准备任何数据/环境并在呼叫后处理结果

  • 开启/关闭资源

    • permission check
    • interrupt action that takes too long
    • run action in separate thread or even in context of different process or event on other machine
    • monitoring
    • preparing any data / environment before call and processing results after call
    • opening / closing resources
    • 编辑

      虽然自从我给出这个答案已经很多年了,但我决定添加以下内容以使答案更加完整。

      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天全站免登陆