Spring Boot auto-configures Spring MVC with sensible defaults, but most production applications need to adjust behavior: tuning how HTTP messages are read and written, customizing serialization, rendering templates, handling exceptions globally, or uploading files. This guide walks through the most common Spring MVC customization tasks in a Spring Boot application.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.
Custom HttpMessageConverters
Spring MVC usesHttpMessageConverter instances to read HTTP request bodies and write HTTP response bodies. Spring Boot registers a set of converters automatically, and you can add to or replace them.
Declare a customizer bean
Declare a Use
ServerHttpMessageConvertersCustomizer bean to add or override converters. The following example adds a converter before the default set:withJsonConverter(...) to replace the default JSON converter instead of adding a new one.If you declare a bean of type
JacksonJsonHttpMessageConverter, it replaces the default Jackson converter rather than supplementing it.Configure the Jackson ObjectMapper
Spring Boot auto-configures aJsonMapper (Jackson’s ObjectMapper equivalent) and exposes properties to tune it without writing code.
Property-based configuration
Jackson features map directly toapplication.properties or application.yaml properties:
| Feature category | Property prefix | Example values |
|---|---|---|
| Serialization | spring.jackson.serialization.<feature> | true, false |
| Deserialization | spring.jackson.deserialization.<feature> | true, false |
| Mapper | spring.jackson.mapper.<feature> | true, false |
| Default property inclusion | spring.jackson.default-property-inclusion | always, non_null, non_empty |
| Date/time | spring.jackson.datatype.datetime.<feature> | true, false |
Programmatic customization
To customize theJsonMapper.Builder used by auto-configuration, declare a JsonMapperBuilderCustomizer bean. Boot’s own customizer has order 0; yours can run before or after it:
JacksonModule application-wide, simply declare it as a Spring bean — it is automatically picked up and applied to all JsonMapper instances created by the builder.
Global exception handling with @ControllerAdvice
Use@ControllerAdvice to centralize exception handling across multiple controllers. Spring Boot integrates this with its own error infrastructure — unhandled exceptions fall through to ErrorController.
Spring Boot also supports RFC 9457 Problem Details. Set
spring.mvc.problemdetails.enabled=true to have Spring MVC produce application/problem+json responses automatically.Custom error pages for specific status codes
Custom error pages for specific status codes
Place static HTML or template files under
src/main/resources/public/error/ (or src/main/resources/templates/error/) named after the status code or a mask:Disabling the whitelabel error page
Disabling the whitelabel error page
To disable the default whitelabel error page entirely, set:You should then provide your own error view or controller, otherwise the servlet container’s default error page is shown.
Serving static files
By default, Spring Boot serves static content from these classpath locations (in order):classpath:/META-INF/resources/classpath:/resources/classpath:/static/classpath:/public/
src/main/resources/static/ or src/main/resources/public/ are automatically served.
To change the URL path pattern for static resources:
Configuring Thymeleaf view resolution
Spring Boot auto-configures Thymeleaf whenspring-boot-starter-thymeleaf is on the classpath. The ThymeleafViewResolver resolves view names by wrapping them with a prefix and suffix.
Default settings:
| Property | Default |
|---|---|
spring.thymeleaf.prefix | classpath:/templates/ |
spring.thymeleaf.suffix | .html |
src/main/resources/templates/ and are automatically picked up. A controller returning the string "home" renders src/main/resources/templates/home.html.
Adding an MVC interceptor
Add interceptors by declaring aWebMvcConfigurer bean — this approach preserves all Spring Boot MVC auto-configuration.
Do not annotate a
WebMvcConfigurer configuration class with @EnableWebMvc. Doing so disables all Spring Boot MVC auto-configuration and requires you to configure everything manually.Switching from Tomcat to Jetty
Spring Boot uses Tomcat by default. To switch to Jetty, exclude the Tomcat starter and add the Jetty starter.- Maven
- Gradle
Configuring multipart file uploads
Spring Boot configures multipart support automatically using properties fromMultipartProperties. Defaults: 1 MB per file, 10 MB per request.
Use the container’s built-in multipart support (the default) rather than Apache Commons FileUpload. It avoids an extra dependency and integrates cleanly with the Servlet API’s
jakarta.servlet.http.Part.