Spring Boot without the web server

后端 未结 16 825
眼角桃花
眼角桃花 2020-11-29 16:50

I have a simple Spring Boot application that gets messages from a JMS queue and saves some data to a log file, but does not need a web server. Is there any way of starting S

16条回答
  •  心在旅途
    2020-11-29 16:59

    You can create something like this:

    @SpringBootApplication
    public class Application {
      public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class).web(false).run(args);
      }
    }
    

    And

    @Component
    public class CommandLiner implements CommandLineRunner {
    
      @Override
      public void run(String... args) throws Exception {
        // Put your logic here
      }
    
    }
    

    The dependency is still there though but not used.

提交回复
热议问题