切入点格式不正确
这个切入点的格式问题是什么?
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:
我认为您正在寻找的切入点表达式更像是这样:
@target
指示符用于匹配标记的类使用给定的注释,@annotation
指示符将过滤到使用denyPackage.Deny
注释注释的方法。再次浏览一下 有关 AspectJ 支持的 Spring 文档 会很有帮助。
:
要匹配任意数量的参数,传递给
执行
切入点指示符的参数定义应该是“..”原始 ="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:
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 thedenyPackage.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 '..'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.
我使用了这样的切入点定义来匹配带注释的方法:
最后一部分
@annotation(deny)
(就像您已经知道的那样,但其他一些可能不知道)是将注释绑定到通知方法名为“deny”的参数。编辑:根据您的更新,我不知道 SafetyCritical 是该类的注释。我想这将在 target() 目标中:
I've used a pointcut definition like this to match annotated methods:
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: