1,创建监听对象
@Data
@AllArgsConstructor
public class ConfirmOrderEvent {
System.out.println("提交订单信息");
}
2,发送事件
@Autowired
private ApplicationContext applicationContext;
// 发送事件
applicationContext.publishEvent(new ConfirmOrderEvent());
3,事件接收
@Component
@AllArgsConstructor
public class ConfirmOrderListener {
@Async//默认同步 @Async可设置为异步处理
@EventListener(ConfirmOrderEvent.class)
@Order(ConfirmOrderOrder.DEFAULT)
public void defaultConfirmOrderEvent(ConfirmOrderEvent event) {
System.out.println("处理订单信息");
}
}