一、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
/