- 正常创建项目
-
application.yaml中配置
spring: main: web-application-type: none - 主类集成CommandLineRunner并重写run方法
-
保持运行:加入
Thread.currentThread().join(); -
最终得到如下结构
@SpringBootApplication public class Application implements CommandLineRunner { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override public void run(String... args) throws Exception { 。。。 Thread.currentThread().join(); } }