自定义注解加AOP完成一个消息已读demo
- 基于spring完成一个注解+AOP简单demo(注解加AOP实现功能)
@EnableAspectJAutoProxy
public class DockingApplication {
public static void main(String[] args) {
SpringApplication.run(DockingApplication.class, args);
}
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MsgTestAnnotation {
}
@Aspect
@Component
@Slf4j
public class MsgTestAspect {
@Pointcut("@annotation(com.xfw.welfare.docking.annotation.MsgTestAnnotation)")
public void msgPointCut() {
}
@After("msgPointCut()")
public void msgAfter() {
log.info("========消息被读取,开始处理,操作redis计数器========");
}
}
@GetMapping("/aop")
@MsgTestAnnotation
public void testMsg(String msg) {
}