1.定义注解
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface LogPoint {
}
2.切面实现
@Slf4j
@Aspect
@Component
@Order(20)
public class LogPointAspect {
//this is test fork
@Before("@annotation(com.trendsi.trace.aop.LogPoint)")
public void before(JoinPoint joinPoint) {
String merchantCode = UserUtils.getUserInfo().getMerchantCode();
log.info("----------------LogPointAspect before:{}", merchantCode);
}
@After("@annotation(com.trendsi.trace.aop.LogPoint)")
public void after(JoinPoint joinPoint) {
String merchantCode = UserUtils.getUserInfo().getMerchantCode();
log.info("---------------LogPointAspect after:{}", merchantCode);
}
}
3.注意事项
aop加载顺序,自定义aop的顺序,要确保在框架提供的aop之后执行。即@order参数需要大于20