切入点格式不正确

发布于 2024-12-21 00:41:38 字数 513 浏览 2 评论 0原文

这个切入点的格式问题是什么?

@Around("execution(* @myPackage.SafetyCritical.*(*))&& @annotation(deny)")

.我忘记添加:例外是“切入点格式不正确:期望'名称模式'(&&之前的最后一个右括号)

作为示例,切入点应该与此类一起使用:

@SafetyCritical
public class SecureClass
{

    public SecureClass(){

    }
    @Deny
    public void isNotAllowed(){
        System.out.println("This should not happen");

    }

    @Allow
    public void isAllowed(){
        System.out.println("Allowed");

    }

}

What is the format problem with this pointcut?

@Around("execution(* @myPackage.SafetyCritical.*(*))&& @annotation(deny)")

.i forgot to add: exception is "Pointcut is not well-formed: expecting 'name pattern' (last closing bracket before &&)

for an example the pointcut should work with this class:

@SafetyCritical
public class SecureClass
{

    public SecureClass(){

    }
    @Deny
    public void isNotAllowed(){
        System.out.println("This should not happen");

    }

    @Allow
    public void isAllowed(){
        System.out.println("Allowed");

    }

}

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

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

发布评论

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

评论(2

一念一轮回 2024-12-28 00:41:38

编辑:

我认为您正在寻找的切入点表达式更像是这样:

@Around("@target(myPackage.SafetyCritical) && @annotation(denyPackage.Deny)")

@target指示符用于匹配标记的类使用给定的注释,@annotation 指示符将过滤到使用 denyPackage.Deny 注释注释的方法。

再次浏览一下 有关 AspectJ 支持的 Spring 文档 会很有帮助。

要匹配任意数量的参数,传递给执行切入点指示符的参数定义应该是“..”

@Around("execution(* myPackage.SafetyCritical.*(..)) && @annotation(deny)")

原始 ="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-ataspectj" rel="nofollow">Spring文档有一些使用这个的例子表示接受任意数量的参数。

另外,我大胆猜测在包名称前面使用“@”符号是不可接受的。你应该删除它。

EDIT:

I think the pointcut expression you are looking for would be more like this:

@Around("@target(myPackage.SafetyCritical) && @annotation(denyPackage.Deny)")

The @target designator is used to match classes that are marked with the given annoation, and the @annotation designator will filter to the methods annotated with the denyPackage.Deny annotation.

Again, a look through the Spring Documentation regarding AspectJ support would be helpful.

ORIGINAL:

To match on any number of arguments, the parameters definition passed to the execution pointcut designator should be '..'

@Around("execution(* myPackage.SafetyCritical.*(..)) && @annotation(deny)")

The Spring documentation has some examples of using this to denote accepting any number of arguments.

Also, I would venture to guess that that having the '@' symbol in front of your package name is not acceptable. You should remove it.

晌融 2024-12-28 00:41:38

我使用了这样的切入点定义来匹配带注释的方法:

@Around("execution(@myPackage.SafetyCritical * *(..)) && @annotation(deny)")

最后一部分 @annotation(deny) (就像您已经知道的那样,但其他一些可能不知道)是将注释绑定到通知方法名为“deny”的参数。

编辑:根据您的更新,我不知道 SafetyCritical 是该类的注释。我想这将在 target() 目标中:

@Around("execution(* *(..)) && @target(myPackage.SafetyCritical) && @annotation(deny)")

I've used a pointcut definition like this to match annotated methods:

@Around("execution(@myPackage.SafetyCritical * *(..)) && @annotation(deny)")

The last part @annotation(deny) (like you already know, but some others may not) is to bind the annotation to the advice method argument named "deny".

Edit: As per your update, I was not aware that SafetyCritical was an annotation on the class. I suppose that would be witin the target() goal then:

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