springspring-bootspring-mvcspring-webflux

What is the purpose of SpringBoot Enum Class WebApplicationType


There is an official document from Spring regarding WebApplicationType

https://docs.spring.io/spring-boot/api/java/org/springframework/boot/WebApplicationType.html

The application layer can choose to set:

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.

I inadvertently forgot to set spring.main.web-application-type=reactive for my spring webflux app.

I also inadvertently forgot to set spring.main.web-application-type=servlet for my spring mvc app.

However, they were both able to serve requests, the app was up and running, and everything seemed fine.

Therefore, I have a question, what is the purpose of this WebApplicationType? It seems that it is doing nothing


Solution

  • This is for selecting which type op application to run. If you have both WebFlux and Spring MVC on the classpath Spring Boot will now know what to start, hence you need to select it. Or you still can have either Spring MVC or Spring WebFlux on the classpath but you are writing a command line application and thus you don't want a server and select NONE.