事件

自定义事件

public class LogEvent extends ApplicationEvent {  ....}

发布事件

监听事件

@EventListener@Async // 异步监听(需要开启异步配置)public void accept(LogEvent event){}// 多事件监听@EventListener(classes = {MyEvent.class, ContextRefreshedEvent.class, ContextClosedEvent.class})public void onMyEventPublished(ApplicationEvent event) {...}
public class LogListener implements ApplicationListener<LogEvent> {    @Async    @Override    public void onApplicationEvent(LogEvent logEvent) {       ...     }}