1、创建发布对象 LoginEvent
2、在要发布对象的地方注入 ApplicationEventPublisher
@Autowired ApplicationEventPublisher publisher;
3、发布 : 调用publisher的publishEvent(Object event)方法
publisher.publishEvent(new LoginEvent())
4、创建事件监听Component
@Component public class LoginEventHandler { Logger log = Logger.getLogger(LoginEventHandler.class); @Async @EventListener public void loginHandler(LoginEvent loginEvent){ //处理 } }
时间: 2024-12-27 08:01:58