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("\n\n\n_________\n\n緩存數據 \n\n ________\n\n\n\n");

            List<TmFlowInfo> flowInfos=flowInfoService.selectList(null);
            FlowContext.initFlow(flowInfos);
            
            //redisCache.setCacheIntegerMap("cityMap", cityMap);
            //redisCache.setCacheIntegerMap("countryMap", countryMap);
        }
    }
    
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM