一、SpringEvent 事件监听
SpringUtils.context().publishEvent(testDemo); 上下文监事件是同步的,如果EventListen 中报错则会阻塞,不继续执行。
事件机制监听的方式有两种:此处用注解演示
- 实现ApplicationListener接口
- EventListener注解形式
//发送代码:
@Slf4j
@RestController
@RequiredArgsConstructor
public class SpringEventTestController {
@RequestMapping("send")
@SaIgnore
public R sendInfo(){
TestDemo testDemo = new TestDemo();
testDemo.setId(1L);
testDemo.setUserId(1L);
testDemo.setValue("send");
log.info("----------------->发送请求");
SpringUtils.context().publishEvent(testDemo);
return R.ok();
}
}
//监听代码
@Slf4j
/
本文详细介绍了RuoYi-Vue-Plus项目中如何使用SpringEvent进行事件监听,包括同步和异步事件处理,并讲解了@TransactionalEventListener在事务中的应用。同时,文章还阐述了@Log日志注解的实现,从记录登录信息到日志切面类的详细过程。
订阅专栏 解锁全文
7453

被折叠的 条评论
为什么被折叠?



