• springmvc-项目启动初始化类


    import com.xxx.platform.bean.TmFlowInfo;
    import com.xxx.platform.cache.RedisCacheUtil;
    import com.xxx.platform.service.TmFlowInfoService;
    import org.apache.log4j.Logger;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.ApplicationListener;
    import org.springframework.context.event.ContextRefreshedEvent;
    import org.springframework.stereotype.Service;
    
    import java.util.List;
    
    /**
     * 监听器,用于项目启动的时候初始化信息
     */
    @Service
    public class StartAddCacheListener implements ApplicationListener<ContextRefreshedEvent>
    {
        //日志
        private final Logger log= Logger.getLogger(StartAddCacheListener.class);
    
        @Autowired
        private TmFlowInfoService flowInfoService;
    
        @Autowired
        private RedisCacheUtil<Object> redisCache;
    
        @Override
        public void onApplicationEvent(ContextRefreshedEvent  event) 
        {
            //spring 启动的时候缓存城市和国家等信息
            if(event.getApplicationContext().getDisplayName().equals("Root WebApplicationContext"))
            {
                System.out.println("
    
    
    _________
    
    缓存数据 
    
     ________
    
    
    
    ");
    
                List<TmFlowInfo> flowInfos=flowInfoService.selectList(null);
                FlowContext.initFlow(flowInfos);
                
                //redisCache.setCacheIntegerMap("cityMap", cityMap);
                //redisCache.setCacheIntegerMap("countryMap", countryMap);
            }
        }
        
    }
  • 相关阅读:
    【码上微服务】- 环境搭建
    【码上微服务】- 环境搭建
    Python 3版本 开始
    算法理解之大数相乘问题
    mycat配置分库分表 读写分离 linux系统
    es6的数组去重
    解析Java为什么不接受合法的HTTPS证书
    为什么要创建开放源码的PlayScala社区?
    实时同步MongoDB Oplog开发指南
    Scala基础
  • 原文地址:https://www.cnblogs.com/fangyuan303687320/p/7840271.html
Copyright © 2020-2023  润新知