springboot 非web项目 Springboot non web project
  • 正常创建项目

  • 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();
      }
    }
    
上一篇
下一篇