项目初始化执行业务逻辑

用初始化监听

@Configuration和@EventListener

package com.wish.biz.pf.productfactory.config;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.wish.biz.pf.productfactory.constants.MpfProductfactoryErrCodeBussCheck;
import com.wish.biz.pf.productfactory.dao.mapper.Pf1005Mapper;
import com.wish.biz.pf.productfactory.model.baseentity.Pf1005;
import com.wish.biz.pf.productfactory.model.baseentity.Pf1005Example;
import com.wish.plat.trans.exception.BizRuntimeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 初始化监听
 *
 */

@Configuration
@Slf4j
public class ListenerConfig {
    
    @Autowired
    private Pf1005Mapper pf1005Mapper;

    @EventListener
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //初始化测试  
        System.out.println("system started, triggered by ContextRefreshedEvent.");
        Pf1005Example example = new Pf1005Example();
        Pf1005Example.Criteria criteria05 = example.createCriteria();
        criteria05.andTemplateNameEqualTo("登陆初始化测试");
        List<Pf1005> pf1005List = pf1005Mapper.selectByExample(example);
        if(ObjectUtils.isEmpty(pf1005List)){
            log.info("初始化");
        }
    }
}

既然是@Configuration  就表示是可以注入的 

发布了50 篇原创文章 · 获赞 2 · 访问量 9403

猜你喜欢

转载自blog.csdn.net/qq_35653822/article/details/104254522
今日推荐