标签:
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){ //处理 } }
标签:
原文地址:http://www.cnblogs.com/oyx305/p/5508167.html