How does a Spring Boot console based application work?

前端 未结 1 585
忘了有多久
忘了有多久 2020-12-13 02:05

If I am developing a rather simple Spring Boot console-based application, I am unsure about the placement of the main execution code. Should I place it in the

相关标签:
1条回答
  • 2020-12-13 02:41

    You should have a standard loader:

    @SpringBootApplication
    public class MyDemoApplication {
        public static void main(String[] args) {
            SpringApplication.run(MyDemoApplication.class, args);
        }
    }
    

    and implement a CommandLineRunner interface with @Component annotation

        @Component
        public class MyRunner implements CommandLineRunner {
    
           @Override    
           public void run(String... args) throws Exception {
    
          }
       }
    

    @EnableAutoConfiguration will do the usual SpringBoot magic.

    UPDATE:

    As @jeton suggests the laters Springboot implements a straight:

    spring.main.web-environment=false
    spring.main.banner-mode=off
    

    See docs at 72.2

    0 讨论(0)
提交回复
热议问题