英文:
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/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论