自定义注解
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface InvokeAnnotation {
String value() default "参数1";
String description() default "参数2";
}
切面方法
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
@Slf4j
public class InvokeAspect {
@Pointcut("@annotation(**.InvokeAnnotation)")
public void invoke() {
}
@Around("invoke() && @annotation(invokeAnnotation)")
public Object invokeAfter(ProceedingJoinPoint joinPoint, InvokeAnnotation invokeAnnotation) throws Throwable {
return joinPoint.proceed();
}
}