1、引入如下依赖:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency>
2、SpringBoot的主配置类实现 CommandLineRunner 接口
@SpringBootApplicationpublic class DemoApplication implements CommandLineRunner {public static void main(String[] args) {new SpringApplicationBuilder().sources(DemoApplication.class) // SpringBoot主配置类.bannerMode(Banner.Mode.CONSOLE) // 在启动之前作相关配置.run(args);// 启动}@Overridepublic void run(String... args) throws Exception {System.out.println("Hello");}}
3、覆写 CommandLineRunner 接口的 run() 方法,在 run 方法中编写具体的处理逻辑
