如何将注解应用于类的每个方法?

huangapple go评论62阅读模式
英文:

How can I apply an annotation to every method of a class?

问题

我有一个在方法级别上测量执行时间的注解。例如,我想知道是否有可能在类级别上创建一个新的注解,将我的“timed”注解应用于该类的每个方法。我对AOP还有些陌生。也许有人有想法?我正在使用:

  • JDK 1.8
英文:

I have an annotation that meters the execution time placed on a method level. I would like to know if it is possible to, for example, create a new annotation on a class level that applies my "timed" annotation on every method of this class. I'm a bit new with AOP. Maybe someone has an idea? I'm using:

  • JDK 1.8

答案1

得分: 0

以下是翻译好的内容:

为了回答我自己的问题,最终我使用了Spring AOP和AspectJ来针对类的每个方法(无需注解)进行处理,以便轻松地进行停用。

类似这样的操作:

链接

英文:

Just to answer my own question, I finally used Srping AOP and AspectJ to target every methods of a class (without annotation) so that it is easily deactivable.

Something like this :

https://howtodoinjava.com/spring-aop/spring-aop-aspectj-xml-configuration-example/

huangapple
  • 本文由 发表于 2020年3月16日 17:15:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/60703174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定