在Spring Boot中,要创建一个非Web应用程序,实现CommandLineRunner并覆盖run()方法
@SpringBootApplication
public class SpringBootConsoleApplication implements CommandLineRunner { public static void main(String[] args) throws Exception { SpringApplication.run(SpringBootConsoleApplication.class, args); } //access command line arguments
@Override
public void run(String... args) throws Exception {
//do something
}
}
pom依赖:spring-boot-starter库