about spring boot how to disable web environment correctly

后端 未结 2 1462
南笙
南笙 2020-12-05 18:53

Spring boot non-web application, when start it has below error

Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWe         


        
2条回答
  •  遥遥无期
    2020-12-05 19:37

    Starting from Spring Boot 2.0

    -web(false)/setWebEnvironment(false) is deprecated and instead Web-Application-Type can be used to specify

    • Application Properties

      spring.main.web-application-type=NONE 
      # REACTIVE, SERVLET
      
    • or SpringApplicationBuilder

      @SpringBootApplication
      public class SpringBootDisableWebEnvironmentApplication {
      
          public static void main(String[] args) {
              new SpringApplicationBuilder(SpringBootDisableWebEnvironmentApplication.class)
                  .web(WebApplicationType.NONE) // .REACTIVE, .SERVLET
                  .run(args);
         }
      }
      

    Where WebApplicationType:

    • NONE - The application should not run as a web application and should not start an embedded web server.
    • REACTIVE - The application should run as a reactive web application and should start an embedded reactive web server.
    • SERVLET - The application should run as a servlet-based web application and should start an embedded servlet web server.

    Courtesy: Another SO Answer

提交回复
热议问题