SpringBoot项目启动完成后自动执行方法

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Order(value = 10)//延后
public class MicroApplicationRunner   implements ApplicationRunner {
//或继承CommandLineRunner

    @Value("${spring.application.name}")
    private String appName;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.warn("加载MicroApplicationRunner...");
        //TODO  
        log.warn(appName+"完成项目配置...");
    }
}

你可能感兴趣的:(Spring,Springboot,spring,boot,java,spring)