spring启动时加载字典表数据放入map
import java.util.HashMap;
import java.util.List; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import cn.zsmy.constant.Constant;
import cn.zsmy.service.tmp.ExDictService;
import cn.zsmy.tmp.extend.entity.ExDict; /**
* 初始化系统参数
*
*/
@Service("dictInit")
public class DictInit { /**存放系统参数*/
public static HashMap<String, String> dictMap = new HashMap<String, String>(); @Autowired
private ExDictService exDictService; /**参数初始化工作*/
public void start() {
injectDictConfigByDb();
} /**读取字典表 */
private void injectDictConfigByDb() {
Constant.MY_LOG.debug("-------Shm:injectDictConfigByDb--开始-------------------");
List<ExDict> exDictList = exDictService.findDict();
if(exDictList != null && exDictList.size() > 0){
for (ExDict exDict : exDictList) {
dictMap.put(exDict.getCode(), exDict.getdValue());
}
}
//打印map
HashMap<String, String> dictMap = (HashMap<String, String>) DictInit.dictMap;
for (HashMap.Entry<String, String> entry : dictMap.entrySet()) {
Constant.MY_LOG.debug("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
Constant.MY_LOG.debug("-------Shm:injectDictConfigByDb--结束-------------------");
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component; import cn.zsmy.constant.Constant; @Component("BeanDefineConfigue")
public class BeanDefineConfigue implements ApplicationListener<ContextRefreshedEvent> { @Autowired
private DictInit dictInit; //YC:当一个ApplicationContext被初始化或刷新触发
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
Constant.MY_LOG.debug("YYCC:START:spring初始化开始======================>");
if (event.getApplicationContext().getParent() == null) {//root application context 没有parent,他就是老大.
Constant.MY_LOG.debug("启动projectInit的start方法进行参数的初始化======================>");
dictInit.start();
} else {
//为什么会执行两次:请参考博文:http://www.cnblogs.com/yucongblog/p/5437744.html
Constant.MY_LOG.debug("spring初始化时,执行onApplicationEvent:event.getApplicationContext().getParent() != null======================>");
}
Constant.MY_LOG.debug("YYCC:END:spring初始化完毕======================>");
} }
spring启动时加载字典表数据放入map的更多相关文章
- Spring启动时加载数据
程序中也许有会有许多常用的,不会经常更改的数据,我们可以在程序初始化的时候就把他们加载,就不用频繁的加载或者查询. 以下是几个常用的,有COPY收集的,也有自己弄. 1. 实现BeanPostProc ...
- Spring 启动时加载资源
Spring加载资源文件目前了解三种, @PostConstruct在Context加载完成之后加载.在创建各个Bean对象之前加载. 实现ApplicationRunner的run方法,Bean加载 ...
- Servlet在启动时加载的tomcat源码(原创)
tomcat 8.0.36 知识点: 通过配置loadOnStartup可以设置Servlet是否在Tomcat启动时加载,以及按值大小进行有序加载,其最小有效值为0,最大有效值为Integer.MA ...
- web.xml中配置启动时加载的servlet,load-on-starup
web.xml中配置启动时加载的servlet,load-on-starup 使用servlet来初始化配置文件数据: 在servlet的配置当中,<load-on-startup>1&l ...
- ElasticSearch 启动时加载 Analyzer 源码分析
ElasticSearch 启动时加载 Analyzer 源码分析 本文介绍 ElasticSearch启动时如何创建.加载Analyzer,主要的参考资料是Lucene中关于Analyzer官方文档 ...
- spring启动容器加载成功后执行调用方法
需求: 由于在微服务架构中各服务之间都是通过接口调用来进行交互的,像很多的基础服务,类似字典信息其实并不需每次需要的时候再去请求接口.所以我的想法是每次启动项目的时候,容器初始化完成,就去调用一下基础 ...
- 设置程序启动时加载的storyboard
这个设置表明:程序启动时会加载Main.storyboard
- Tomcat启动时加载数据到缓存---web.xml中listener加载顺序(优先初始化Spring IOC容器)
JavaWebSpringTomcatCache 最近用到在Tomcat服务器启动时自动加载数据到缓存,这就需要创建一个自定义的缓存监听器并实现ServletContextListener接口,并且 ...
- Tomcat启动时加载数据到缓存---web.xml中listener加载顺序(例如顺序:1、初始化spring容器,2、初始化线程池,3、加载业务代码,将数据库中数据加载到内存中)
最近公司要做功能迁移,原来的后台使用的Netty,现在要迁移到在uap上,也就是说所有后台的代码不能通过netty写的加载顺序加载了. 问题就来了,怎样让迁移到tomcat的代码按照原来的加载顺序进行 ...
随机推荐
- linux运维中常用的指令
一.终端中常用的快捷键 man界面中的快捷键: ?keyword 向上搜索关键词keyword,n向下搜索,N继续向上搜索 /keyword 向下搜索关键词keyw ...
- Python9-递归函数-day17
# 计算方法:人脑复杂,计算机简单#查找:找数据#排序#最短路径#我们学习的算法都是过去时#要了解基础的算法,才能创造出更好的算法#不是所有的事情都能套用现成的方法解决的# 有些时候会用到学过的算法只 ...
- 设置 TabBarItemt图片颜色
UIImage *discussSelectedImage = [UIImage imageNamed:@"discuss_selected"];//设置图片不渲染 discuss ...
- LeetCode(109) Convert Sorted List to Binary Search Tree
题目 Given a singly linked list where elements are sorted in ascending order, convert it to a height b ...
- python中map()函数的用法讲解
map函数的原型是map(function, iterable, -),它的返回结果是一个列表. 参数function传的是一个函数名,可以是python内置的,也可以是自定义的. 参数iterabl ...
- PAT Basic 1051
1051 复数乘法 复数可以写成 (A+Bi) 的常规形式,其中 A 是实部,B 是虚部,i 是虚数单位,满足 i2=−1:也可以写成极坐标下的指数形式 (R×e(Pi)),其中 R 是复 ...
- JQuery中xxx is not a function或者can not find $
在项目中,遇到以上两个错误,反复折腾了好久,js代码写得没有问题,jquery的文件也引入了,就是反复的报告错误,xxx is not a function.如图: 就是这样的错误,shake is ...
- Uiautomator简介及其环境搭建、测试执行
UiAutomator框架使用指南 UiAutomator是Google开发的自动化测试工具,通过UI创建自动化测试代码,来测试界面(UI)的有效功能,可以针对应用程序运行在一个或更多的设备上.我们并 ...
- Django框架简介及模板Template,filter
Django框架简介 MVC框架和MTV框架 MVC,全名是Model View Controller,是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View) ...
- luogu3755 [CQOI2017]老C的任务
扫描线水题. #include <algorithm> #include <iostream> #include <cstdio> using namespace ...