AspectJ 使用 AspectJ 注释公开注释值

发布于 2024-09-30 18:41:03 字数 458 浏览 1 评论 0原文

我使用 AspectJ 注释而不是编写实际的方面文件。我想向我的建议公开一个注释值。

我目前有这个,但它没有公开 MyAnnotation 中的值

@Before("execution(@MyAnnotation * * (..))")
public void intercept(JoinPoint jp) {
 ...
}

我的想法是这样的:

@Before("execution(@MyAnnotation * * (..)) && @this(MyAnnotation)")
public void intercept(JoinPoint jp, MyAnnotation myAnnotation) {
 ...
}

这显然有一个语法错误,但想知道我是否接近。使用 AspectJ 注释来执行此操作时,我似乎找不到示例语法。

I'm using AspectJ annotations instead of writing actual aspect files. I want to expose an annotation value to my advice.

I currently have this but it it doesn't expose the values inside MyAnnotation

@Before("execution(@MyAnnotation * * (..))")
public void intercept(JoinPoint jp) {
 ...
}

What I was thinking was something like this:

@Before("execution(@MyAnnotation * * (..)) && @this(MyAnnotation)")
public void intercept(JoinPoint jp, MyAnnotation myAnnotation) {
 ...
}

This clearly has a syntax error but was wondering if I was close. I can't seem to find an example syntax when using AspectJ annotations to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雪碎 2024-10-07 18:41:03

当您应该使用标识符时,您正在使用类型。正确的代码是:

@Before("execution(@MyAnnotation * * (..)) && @this(myAnnotation)")
public void intercept(JoinPoint jp, MyAnnotation myAnnotation) {
 ...
}

You are using type, when you should be using an identifier. The correct code is:

@Before("execution(@MyAnnotation * * (..)) && @this(myAnnotation)")
public void intercept(JoinPoint jp, MyAnnotation myAnnotation) {
 ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文