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; @Component
public 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();
}
}
}
} }
Spring监听,ApplicationListener的更多相关文章
- spring监听机制——观察者模式的应用
使用方法 spring监听模式需要三个组件: 1. 事件,需要继承ApplicationEvent,即观察者模式中的"主题",可以看做一个普通的bean类,用于保存在事件监听器的业 ...
- Spring的事件监听ApplicationListener
ApplicationListener是Spring事件机制的一部分,与抽象类ApplicationEvent类配合来完成ApplicationContext的事件机制. 如果容器中存在Applica ...
- Spring事件监听ApplicationListener源码流程分析
spring的事件机制是基于观察者设计模式的,ApplicationListener#onApplicationEvent(Event)方法,用于对事件的处理 .在容器初始化的时候执行注册到容器中的L ...
- Spring 监听
Spring 中的事件监听的实现 这里我们不讨论事件监听的机制的原理,我们只讨论如何在项目中实现时间监听. spring的事件监听是基于观察者模式.设计开发中.如下类与接口是我们必须要使用的. App ...
- SpringMVC 事件监听 ApplicationListener
1. 实现 ApplicationListener<T> 接口(T为监听类型,稍后会列出具体可监听事件) 2. 将该自定义监听类,注册为Spring容器组件.(即将该类注入Spring容器 ...
- spring监听与IBM MQ JMS整合
spring xml 的配置: 文件名:applicationContext-biz-mq.xml <?xml version="1.0" encoding="UT ...
- spring源码-事件&监听3.6
一.spring中的发布与监听模式,是我们最常用的一种观察者模式.spring在其中做了很多优化,目的就是让用户更好的使用事件与监听的过程. 二.常用的事件与监听中涉及到的接口和类为:Applicat ...
- Spring的事件监听机制
最近公司在重构广告系统,其中核心的打包功能由广告系统调用,即对apk打包的调用和打包完成之后的回调,需要提供相应的接口给广告系统.因此,为了将apk打包的核心流程和对接广告系统的业务解耦,利用了spr ...
- 十一、Spring之事件监听
Spring之事件监听 ApplicationListener ApplicationListener是Spring事件机制的一部分,与抽象类ApplicationEvent类配合来完成Applica ...
随机推荐
- html固定表头,表单内容垂直循环滚动
<!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8 ...
- Kali安装问题解决方案
一.对今天安装Kalilinux 失败的原因做一个简单的总结, 1.安装之前的电脑状况,电脑配置Windows7 64位旗舰版配置,虚拟版本是VMware Workstation Pro14 ver ...
- idea导入java项目
https://blog.csdn.net/m0_37106742/article/details/70154244 ( 主要 )https://blog.csdn.net/u012099869/ar ...
- java web 项目中 简单定时器实现 Timer
java web 项目中 简单定时器实现 Timer 标签: Java定时器 2016-01-14 17:28 7070人阅读 评论(0) 收藏 举报 分类: JAVA(24) 版权声明:本文为博 ...
- Windows批处理命令用法
阅读下面文字需要一定的dos基础概念,象:盘符.文件.目录(文件夹).子目录.根目录.当前目录 每个命令的完整说明请加 /? 参数参考微软的帮助文档可以看到,在 /? 帮助里,"命令扩展名& ...
- 论文阅读笔记三十七:Grid R-CNN(CVPR2018)
论文源址:https://arxiv.org/abs/1811.12030 开源代码:未公开 摘要 本文提出了目标检测网络Grid R-CNN,其基于网格定位机制实现准确的目标检测.传统方法主要基于回 ...
- docker 给none镜像打镜像
1.遇到none的镜像打tag方式: docker tag + docker ID + 命名:版本名 案例:docker tag 41b7307026c0 gitlab:test 这就 ...
- 学习Maven POM
什么是POM POM stands for "Project Object Model".It is an XML representation of a Maven projec ...
- js里添加的标签
js里添加的标签.网页加载此标签绑定的js函数时,由于没有标签,故无法执行函数. 例如: js中添加了一个button: html1 += "<td><button typ ...
- TensorFlow框架(一) 张量、计算图、会话
参考:中国大学MOOC 北京大学 曹健<TensorFlow笔记> 基于TensorFlow的NN:用张量表示数据,用计算图搭建神经网络,用会话执行计算图,优化线上的权重(参数),得到模型 ...