項目啓動就加載的信息

項目啓動就加載信息,通過實現CommandLineRunner類,來加載

package com.xxx.customerserviceapi.common.config;

import com.xxx.base.util.CommonUtil;
import com.xxx.common.base.constant.CommonConstant;
import com.xxx.common.base.entity.Product;
import com.xxx.common.redis.RedisDao;
import com.xxx.customerserviceapi.dao.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 初始化 信息
 */
@Component
public class InitConfigApi implements CommandLineRunner {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private RedisDao redisDao;

    @Override
    public void run(String... strings) throws Exception {
        //查詢產品線信息,存到redis中
        List<Product> list = productMapper.getList();
        for(Product product:list){
            redisDao.put(CommonConstant.REDIS_PRODUCTLIST, product.getSign(), CommonUtil.beanToString(product));
        }
    }


}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章