Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义注释上的Spring切入点XML表达式_Spring_Aop_Aspectj - Fatal编程技术网

自定义注释上的Spring切入点XML表达式

自定义注释上的Spring切入点XML表达式,spring,aop,aspectj,Spring,Aop,Aspectj,我有一个自定义注释,如下所示: @Inherited @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface MyCustomAnnotation { } 在Spring XML配置中,我有以下内容: <aop:pointcut id="fooPointcut" expression="@annotation(com.

我有一个自定义注释,如下所示:

@Inherited
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyCustomAnnotation {
}
在Spring XML配置中,我有以下内容:

            <aop:pointcut id="fooPointcut" expression="@annotation(com.foo.blah.MyCustomAnnotation)"/>

这将仅在方法注释上匹配。如何调整spel以同时捕获类型/类注释?

使用(com.foo.blah.MyCustomAnnotation)中的
@来

限制匹配到具有给定注释的类型内的连接点

组合切入点表达式将变成:

@annotation(com.foo.blah.MyCustomAnnotation) || @within(com.foo.blah.MyCustomAnnotation)
有关更多参考,请参见中的。还要注意的是,它不支持完整的AspectJ切入点,只支持一个

还要注意,AspectJ中的
@annotation(com.foo.blah.MyCustomAnnotation)
将匹配

连接点主体具有给定注释的所有连接点


这意味着它将匹配方法执行和方法调用。在Spring AOP中,它只匹配方法执行,但是最好编写在更广范围内有效的切入点表达式,所以不要忘记使用
执行(…)
切入点来限制切入点。

感谢详细的响应-这非常有效。我很高兴听到这个消息!介意接受我的回答并投票吗?:)