我有一个这样的注释(在Spring Boot 2中:)>
package com.test; @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface MyAnnotation { }
和元注释:
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @MyAnnotation public @interface MyEndpoint{ }
如何定义一个方面以便在具有@MyAnnotation的每个方法之前执行?
如果我在下面定义的话,
@Before("execution(public * *(..)) && @annotation(myAnnotation)") public void authorize(JoinPoint pjp, MyAnnotation myAnnotation) { }
然后仅调用方法
authorize
@MyAnnotation() public myMethod(){}
并且在这种情况下不是:
@MyEndpoint() public myMethod() {}
谢谢
我有一个这样的注释(在Spring Boot 2中):package com.test; @Target({ElementType.METHOD,ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@继承的公共@interface MyAnnotation {} ...
@Inherited
批注仅适用于从带注释的类到子类,在任何其他情况下均不适用。我对此进行了详细的解释here,还显示了AspectJ解决方法的外观。您可以根据情况进行调整。 但是