Spring Boot gives you two distinct web stacks to choose from: the servlet-based Spring MVC stack for traditional, thread-per-request processing, and the reactive Spring WebFlux stack for non-blocking, asynchronous workloads. Both are first-class citizens with auto-configuration, embedded server support, and identical support for static content, template engines, and error handling.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
- Spring MVC (servlet)
- Spring WebFlux (reactive)
Spring MVC runs on the servlet API and uses a thread-per-request model. It is the right choice when you need maximum compatibility with the existing Spring ecosystem or when your team is most familiar with imperative programming.Add the starter to your project:A typical Spring Boot provides auto-configuration for Spring MVC that works well with most applications. It replaces the need for
pom.xml
@RestController that serves JSON data:MyRestController.java
@EnableWebMvc — the two cannot be used together. The auto-configuration provides:ContentNegotiatingViewResolverandBeanNameViewResolverbeans- Static resource serving including WebJars support
- Automatic registration of
Converter,GenericConverter, andFormatterbeans HttpMessageConverterswith Jackson for JSON (and JAXB for XML when available)- Static
index.htmlsupport
Embedded servers
Spring Boot bundles an embedded server so you do not need to deploy to an external application server. The server to use is determined by the starter you add.Tomcat
Default server for
spring-boot-starter-web. Widely used, production-proven servlet container.Jetty
Alternative for the servlet stack. Swap by excluding
spring-boot-starter-tomcat and adding spring-boot-starter-jetty.Reactor Netty
Default server for
spring-boot-starter-webflux. Fully non-blocking, best suited for reactive workloads.8080 by default. Configure it in application.properties or application.yaml:
application.yaml
Error handling
By default, Spring Boot provides an/error mapping that handles all errors in a sensible way. For machine clients it produces a JSON response with the error details, HTTP status, and exception message. For browser clients, a “whitelabel” error page renders the same data in HTML.
As of Spring Framework 6.0, RFC 9457 Problem Details is supported. Enable it with:
application.yaml
application/problem+json:
/error directory of your static resources:
Static content
By default, Spring Boot serves static content from/static, /public, /resources, or /META-INF/resources on the classpath. Resources are mapped on /**.
Customize the path pattern:
application.yaml
application.yaml
Template engines
Spring Boot includes auto-configuration support for the following templating engines for rendering dynamic HTML:| Engine | Dependency |
|---|---|
| Thymeleaf | spring-boot-starter-thymeleaf |
| FreeMarker | spring-boot-starter-freemarker |
| Mustache | spring-boot-starter-mustache |
| Groovy | spring-boot-starter-groovy-templates |
src/main/resources/templates.
CORS configuration
Cross-origin resource sharing (CORS) can be configured per-controller using@CrossOrigin annotations, or globally by registering a WebMvcConfigurer bean:
MyCorsConfiguration.java
Spring GraphQL
Spring Boot auto-configures Spring for GraphQL whenspring-boot-starter-graphql is on the classpath. Because GraphQL is transport-agnostic, you also need a web starter to expose the API.
application.yaml
src/main/resources/graphql/** with a .graphqls or .gqls extension. Spring Boot picks them up automatically.
Implement query handlers using annotated @Controller classes:
GreetingController.java
POST /graphql by default. Enable the WebSocket endpoint by setting spring.graphql.websocket.path.
API versioning
Both Spring MVC and Spring WebFlux support API versioning to evolve HTTP APIs over time. Configure versioning using properties:application.yaml
If your setup requires multiple strategies, such as header and query parameter combined, declare the order programmatically by overriding the
configureApiVersioning method in a WebMvcConfigurer.