原创

SpringBoot-ApplicationRunnerImpl-服务启动后执行调用-处理数据-打印配置参数

package cn.jiangjiesheng.edu.core;

import cn.jiangjiesheng.edu.config.BizzConfig;
import cn.jiangjiesheng.edu.service.UserIntermediateService;
import cn.jiangjiesheng.edu.service.common.HandleTableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Order(value = 1)
public class ApplicationRunnerImpl implements ApplicationRunner {

    @Autowired
    private HandleTableService handleTableService;
    @Autowired
    private UserIntermediateService userIntermediateService;
    @Autowired
    private BizzConfig bizzConfig;

    @Override
    public void run(ApplicationArguments args) {
        log.info("开始检查各种参数 & 配置 & 脚本");
        log.info("关键参数打印开始...");
        log.info("业务相关配置bizzConfig:{}", bizzConfig);
        log.info("关键参数打印结束");

        handleTableService.checkAddTableEduSyncMqPaasUser();
        userIntermediateService.handledHistoryNodeIdList();
    }
}

上面的优先级不高,且是异步的,
改到启动类后调用
try {
ApplicationRunnerService applicationRunnerService =
(ApplicationRunnerService) ContextUtil.getBean("applicationRunnerService");
applicationRunnerService.runCheck();
} catch (Exception e) {
e.printStackTrace();
}

@Service("applicationRunnerService")
@Slf4j
@Order(value = 1)
public class ApplicationRunnerService {

public void runCheck() {
try {
////////////
} catch (Exception e) {
log.error("ApplicationRunnerService runCheck 出现异常:{}", e);
}
}

正文到此结束
本文目录