1.监听容器得某个事件,被动执行代码。
ApplicationListener<ContextRefreshedEvent>实现了这个接口,
public void onApplicationEvent(ContextRefreshedEvent event) {
if (isDelay() && !isExported() && !isUnexported()) {
if (logger.isInfoEnabled()) {
logger.info("The service ready on spring started. service: " + getInterface());
}
export();
}
}
在这样得方法中执行容器刷新得方法。
2.主动发布一个事件,需要先获取事件发布者,实现applicationEventPublisherAware,然后在发布得入口去发布一个事件。
3.被发布得事件,要继承ApplicationEvent类。