- CommandLineRunner和ApplicationRun
- CommandLineRunner,ApplicationRun
- CommandLineRunner与ApplicationRun
- Spring Boot ApplicationRunner &
- Spring Boot之 CommandLineRunner、A
- spring-boot CommandLineRunner、Ap
- SpringBoot之CommandLineRunner与App
- SpringBoot 启动时加载类 ApplicationRun
- springboot 特定code 在SpringApplica
- Spring Boot CommandLineRunner和Ap
Spring boot会在上下问初始化后,调用所有的Runner 。
主要接口
public interface CommandLineRunner {
void run(String... args) throws Exception;
}
public interface ApplicationRunner {
void run(ApplicationArguments args) throws Exception;
}
只要参数不同,在使用的时候我们只需根据需求实现任意一个接口即可
package cn.huanuo;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
@Component
public class MyApplicationRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println(args);
}
}
执行顺序,如果实现了多个Runner 可以使用@Order 执行执行顺序,Spring boot 在遍历所有的Runner后会进行排序处理。
网友评论