定义一个自定义注解
// 自定义注解
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ApprovalFlowAnno {
String value() default "";
}
有该注解的方法作为切点
import com.fulongtech.pms.annotation.ApprovalFlowAnno;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@Aspect
@Component
@Slf4j
public class ApprovalFlowAspect {
@Autowired
private RestTemplate restTemplate;
@Pointcut("@annotation(com.fulongtech.pms.annotation.ApprovalFlowAnno)")
public void methodPointCut() { }
@Before(value = "methodPointCut()&&@annotation(approvalFlowAnno)")
public void before(final JoinPoint jointPoint, final ApprovalFlowAnno approvalFlowAnno) {
final Object[] args = jointPoint.getArgs();
log.info("实体类对象的Json字符串:【{}】", args.toString());
}
}