Spring 的 ApplicationEvent and ApplicationListener 、spring框架加载完成后执行上下文刷新事件(ContextRefreshedEvent)
来源:互联网 发布:六壬课推算法 编辑:程序博客网 时间:2024/05/16 14:21
ApplicationContext在运行期会自动检测到所有实现了ApplicationListener的bean对象,并将其作为事件接收对象。当ApplicationContext的publishEvent方法被触发时,每个实现了ApplicationListener接口的bean都会收到ApplicationEvent对象,每个ApplicationListener可根据事件类型只接收处理自己感兴趣的事件,比如上面的StudentAddListener只接收StudentAddEvent事件。
http://blog.csdn.net/liuwenbo0920/article/details/7263766(非常好)
http://yangyongbyjava.iteye.com/blog/1600581
http://www.th7.cn/Program/java/201408/271385.shtml(ApplicationListener接口中的onApplicationEvent被调用两次解决方案)
Spring监听 ApplicationListener
import java.util.HashMap;import java.util.Map;import org.apache.commons.lang3.StringUtils;import org.apache.log4j.Logger;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.beans.factory.annotation.Qualifier;import org.springframework.context.ApplicationContext;import org.springframework.context.ApplicationListener;importorg.springframework.context.event.ContextRefreshedEvent;import org.springframework.stereotype.Component;@Componentpublic class InitDataListener implements ApplicationListener { //ContextRefreshedEvent为初始化完毕事件 private static final Logger LOGGER =Logger .getLogger(InitDataListener.class); // 缓存管理器 @Autowired @Qualifier("dictCacheManager") private DictCacheManager dictCacheManager; @Override public voidonApplicationEvent(ContextRefreshedEvent event) { final ApplicationContext app= event.getApplicationContext(); if (null ==app.getParent() &&"Root WebApplicationContext".equals(app.getDisplayName())) { //当存在父子容器时,此判断很有用 //读取字典配置 Map config =new HashMap(); try { config= PathUtil.getProperties("dataDictConfig.properties"); finalString mKey = config.get("dataDictKey"); if(StringUtils.isNotBlank(mKey)) { DictCacheManager.M_KEY= mKey; } } catch(Exception e) { LOGGER.error("Load\"dataDictConfig.properties\" failure!", e); } //判断是否立即加载数据字典到Redis if("false".equals(config.get("lazyLoad"))) { //立即加载数据字典数据到Redis缓存服务器 dictCacheManager.init(); } } }}}
0 0
- Spring 的 ApplicationEvent and ApplicationListener 、spring框架加载完成后执行上下文刷新事件(ContextRefreshedEvent)
- Spring 的 ApplicationEvent and ApplicationListener
- Spring 的 ApplicationEvent and ApplicationListener
- Spring 的 ApplicationEvent and ApplicationListener
- Spring 的 ApplicationEvent and ApplicationListener
- Spring 的 ApplicationEvent ,ApplicationListener,ApplicationContextAware
- Spring 的 ApplicationEvent和ApplicationListener
- Spring的ApplicationEvent和ApplicationListener
- Spring透过ApplicationListener来触发contextrefreshedevent事件
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
- Spring的监听事件ApplicationListener和ApplicationEvent及@EventListener用法
- Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法
- Spring ApplicationContext事件机制:ApplicationEvent与ApplicationListener
- Spring 通过ApplicationListener&ApplicationEvent实现事件监听
- Cocos2d-JS事件处理机制
- codeigniter MySQL加减运算
- span 换行出现的间隔
- ios 动态设置Cell的高度
- web.xml中设置统一的自定义错误页面
- Spring 的 ApplicationEvent and ApplicationListener 、spring框架加载完成后执行上下文刷新事件(ContextRefreshedEvent)
- 敏捷个人指南(必读--很完善的一个---敏捷个人系统)
- 网络芯片应用:GPS公交车行驶记录仪
- 大端模式与小端模式
- 软考专题模块:常用算法
- Android电源管理-Healthd (1)
- coursera Machine Learning, Andrew Ng
- Java 泛型参数 向上转型
- 消息推送