1.定义注解

  1. @Documented
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Target({ElementType.METHOD, ElementType.TYPE})
  4. public @interface LogPoint {
  5. }

2.切面实现

  1. @Slf4j
  2. @Aspect
  3. @Component
  4. @Order(20)
  5. public class LogPointAspect {
  6. //this is test fork
  7. @Before("@annotation(com.trendsi.trace.aop.LogPoint)")
  8. public void before(JoinPoint joinPoint) {
  9. String merchantCode = UserUtils.getUserInfo().getMerchantCode();
  10. log.info("----------------LogPointAspect before:{}", merchantCode);
  11. }
  12. @After("@annotation(com.trendsi.trace.aop.LogPoint)")
  13. public void after(JoinPoint joinPoint) {
  14. String merchantCode = UserUtils.getUserInfo().getMerchantCode();
  15. log.info("---------------LogPointAspect after:{}", merchantCode);
  16. }
  17. }

3.注意事项

aop加载顺序,自定义aop的顺序,要确保在框架提供的aop之后执行。即@order参数需要大于20