spring boot(21) : 项目启动完成之后执行任务

参考 : https://www.cnblogs.com/zuidongfeng/p/9926471.html 

import com.aliyun.et.industry.pangang.biz.service.ColdConfigService;
import com.aliyun.et.industry.pangang.common.consts.Configs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @Auther: liyue
 * @Date: 2019/7/9 11:35
 * @Description:
 */
@Component
public class InitImpl implements ApplicationRunner {

    private Logger logger = LoggerFactory.getLogger(ApplicationRunner.class);

    @Autowired
    private ColdConfigService configService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        logger.info("项目启动完成,开始执行初始化任务...");
        logger.info("执行由于分布式部署限定定时任务只执行一次的配置初始化...");
        configService.zeroing();

    }
}

 

END。

你可能感兴趣的:(springboot)