【发布时间】:2020-07-03 17:19:45
【问题描述】:
我有一个这样的注释(在 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 annotations aop aspectj spring-annotations