用于构造函数调用的AspectJ Pointcut

编程入门 行业动态 更新时间:2024-10-22 13:57:53
本文介绍了用于构造函数调用的AspectJ Pointcut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写一条建议,以使用自定义注释来拦截对类的构造函数的调用:

I am trying to write an advice to intercept the calls to constructors of a class with my custom annotation:

@MyCustomAnnotation public class SomeClass { public SomeClass(Foo a, Bar b){ ... } public SomeClass(Foo a){ this(a, null); } }

我通常看到一个如何拦截构造函数调用的示例:

I see an example of how to intercept constructor calls, in general:

@Before("execution(*.new(..))")

我如何更新它以仅对使用我的 @MyCustomAnnotation 批注进行批注的类执行

How do I update this to only execute for classes that are annotated with my @MyCustomAnnotation annotation

推荐答案

我将其用于方法调用:

within(@MyCustomAnnotation *)

因此,最终的方面代码将是:

So, the resulting aspect code would be:

@Before("execution(*.new(..)) && within(@MyCustomAnnotation *)")

或者,尝试以下操作:

@Pointcut("execution(@MyCustomAnnotation *.new(..))")

我在这里指的是文档: blog.espenberntsen/2010/03/20/aspectj-cheat-sheet/

I am referring to the documentation here: blog.espenberntsen/2010/03/20/aspectj-cheat-sheet/

而且,它应该在理论上可行,但是我没有任何运气.

and, it should work in theory, but I am not having any luck.

更多推荐

用于构造函数调用的AspectJ Pointcut

本文发布于:2023-10-27 23:07:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   AspectJ   Pointcut

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!