1.首先在web.xml配置
<listener>
<listener-class>DataDictionaryListener</listener-class>
</listener>
2.书写DataDictionaryListener类
public class DataDictionaryListener extends ContextLoader implements ServletContextListener{
private ArrayList<String> codeArrayList = new ArrayList<String>();//数据字典Code列表
@Override
public void contextInitialized(ServletContextEvent sce) {
//Spring上下文获取及Bean获取
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
DataDictionaryService dataDictionaryService = (DataDictionaryService) applicationContext.getBean("dataDictionaryService");
ServletContext servletContext = sce.getServletContext();
//查询获取数据库所有数据字典Code列表
try {
codeArrayList = dataDictionaryService.getDataDictionaryCodeList();
}catch (Exception e){
System.out.println("============项目启动获取数据字典Code列表出错==================");
e.printStackTrace();
}
//循环CodeList初始化数据字典数据之内存中
try {
for (String code : codeArrayList) {
servletContext.setAttribute(code, dataDictionaryService.getDataDictionaryByStr(code));
}
}catch (Exception ex){
System.out.println("============项目启动存储数据字典列表至内存出错==================");
ex.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
closeWebApplicationContext(sce.getServletContext());
}
}
3.从内存中取出每个code对应的list集合dataDictionaryService方法
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
arrayList = (ArrayList<DataDictionary>) servletContext.getAttribute(code);
获取到该code对应的arrayList数据。
最新评论
徒弟可以A师傅,学生可以A老师,为什么外包不能A正式,我觉得很正常。异性相吸这是宇宙真理
PHP天下第一(狗头叼花)
第一个不需要关注公主号直接给激活码的帖子!
客户端超时断开后,服务端如果没有设置超时机制,那也会继续等待处理,万一这期间有消息到了,那不是就接受到消息处理了,但是也没有办法返回到客户端,导致消息丢失。
企业级GO项目开发实战 Kubernetes权威指南 第六版
https://pan.baidu.com/s/1q3bnTncIACKoTZFxvx7BQw?pwd=ii7n
RabbitMQ精讲,项目驱动落地,分布式事务拔高 有吗?
Spring Cloud Alibaba 微服务架构实战 https://pan.baidu.com/s/1jF5voFRoeF0lYAzAPBWSbw?pwd=chqk