spring启动时加载字典表数据放入map
2017-01-17 11:51
274 查看
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的web应用启动加载数据字典方法
- Spring Boot 启动加载数据 CommandLineRunner
- Spring Boot 启动加载数据 CommandLineRunner
- spring-boot启动时加载数据 CommandlineRunner
- Spring Boot 启动加载数据 CommandLineRunner
- Spring Boot 启动加载数据 CommandLineRunner
- Spring启动时加载数据
- Spring Boot 启动加载数据 CommandLineRunner
- 关于spring boot 的启动加载 一些初始化数据
- 在项目启动时 使用监听器加载所有字典表数据
- spring boot启动加载数据
- springboot启动加载数据
- Spring Boot 启动加载数据 CommandLineRunner
- Spring:启动项目时加载数据库数据(总结)
- Spring Boot 启动加载数据 CommandLineRunner
- (一)Spring boot CommandLineRunner的基本使用:启动加载数据
- Spring Boot 启动加载数据 CommandLineRunner
- Spring Boot 启动加载数据 CommandLineRunner
- Spring Boot 启动加载数据 CommandLineRunner