Spring boot CommandLineRunner接口

介绍

Spring boot的CommandLineRunner接口主要用于实现在应用初始化后,去执行一段代码块逻辑,这段初始化代码在整个应用生命周期内只会执行一次

如何使用

和@Component注解一块使用

@Component
@Sl4j
public class ApplicationStartupRunner implements CommandLineRunner {
 
    @Override
    public void run(String... args) throws Exception {
        log.info("ApplicationStartupRunner run method Started !!");
    }
}