Starter for building web, including RESTful, applications using Spring MVC with embedded Tomcat server.
—
Configure Spring Boot web application behavior through application properties and programmatic configuration.
Configure the embedded web server (port, SSL, compression, etc.).
# Core server settings
server.port=8080
server.address=0.0.0.0
server.servlet.context-path=/myapp
server.servlet.application-display-name=My Application
# Server headers and limits
server.server-header=MyServer/1.0
server.max-http-request-header-size=8KB
# Shutdown behavior
server.shutdown=GRACEFUL
# Options: GRACEFUL, IMMEDIATE
# Forward headers strategy (for proxy setups)
server.forward-headers-strategy=FRAMEWORK
# Options: NATIVE, FRAMEWORK, NONEUsage Examples:
# Production server configuration
server.port=8443
server.servlet.context-path=/api/v1
server.shutdown=GRACEFUL
server.forward-headers-strategy=NATIVE
# Development server configuration
server.port=8080
server.servlet.context-path=/
server.shutdown=IMMEDIATEConfigure SSL/TLS encryption for HTTPS connections.
# SSL/TLS configuration
server.ssl.enabled=true
server.ssl.key-store=classpath:keystore.p12
server.ssl.key-store-password=changeit
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=tomcat
# Trust store configuration
server.ssl.trust-store=classpath:truststore.p12
server.ssl.trust-store-password=changeit
server.ssl.trust-store-type=PKCS12
# SSL protocol and cipher configuration
server.ssl.protocol=TLS
server.ssl.enabled-protocols=TLSv1.2,TLSv1.3
server.ssl.ciphers=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
# Client certificate authentication
server.ssl.client-auth=NEED
# Options: NEED, WANT, NONEEnable HTTP/2 support and response compression.
# HTTP/2 configuration
server.http2.enabled=true
# Response compression
server.compression.enabled=true
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml
server.compression.excluded-user-agents=gozilla,traviata
server.compression.min-response-size=2KBConfigure Spring MVC behavior and request handling.
# Message codes resolver format
spring.mvc.message-codes-resolver-format=PREFIX_ERROR_CODE
# Options: PREFIX_ERROR_CODE, POSTFIX_ERROR_CODE
# Request handling
spring.mvc.dispatch-trace-request=false
spring.mvc.dispatch-options-request=true
spring.mvc.publish-request-handled-events=true
spring.mvc.log-request-details=false
spring.mvc.log-resolved-exception=false
# Static resources path pattern
spring.mvc.static-path-pattern=/**
spring.mvc.webjars-path-pattern=/webjars/**
# Servlet configuration
spring.mvc.servlet.path=/
spring.mvc.servlet.load-on-startup=-1
# View resolution
spring.mvc.view.prefix=
spring.mvc.view.suffix=
# Exception handling
spring.mvc.throw-exception-if-no-handler-found=false
spring.mvc.ignore-default-model-on-redirect=trueConfigure JSON serialization and deserialization behavior.
# Jackson JSON configuration
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT
spring.jackson.locale=
spring.jackson.joda-date-time-format=
spring.jackson.property-naming-strategy=
# Serialization settings
spring.jackson.serialization.indent-output=false
spring.jackson.serialization.write-dates-as-timestamps=true
spring.jackson.serialization.write-durations-as-timestamps=false
spring.jackson.serialization.write-char-arrays-as-json-arrays=false
spring.jackson.serialization.write-enums-using-to-string=false
spring.jackson.serialization.fail-on-empty-beans=true
# Deserialization settings
spring.jackson.deserialization.fail-on-unknown-properties=true
spring.jackson.deserialization.fail-on-null-for-primitives=false
spring.jackson.deserialization.fail-on-numbers-for-enums=false
spring.jackson.deserialization.accept-single-value-as-array=false
spring.jackson.deserialization.unwrap-single-value-arrays=false
# Parser features
spring.jackson.parser.allow-comments=false
spring.jackson.parser.allow-yaml-comments=false
spring.jackson.parser.allow-unquoted-field-names=false
spring.jackson.parser.allow-single-quotes=false
# Generator features
spring.jackson.generator.write-numbers-as-strings=false
spring.jackson.generator.escape-non-ascii=false
# Mapper features
spring.jackson.mapper.sort-properties-alphabetically=false
spring.jackson.mapper.propagate-transient-marker=falseConfigure URL path matching and content type negotiation.
# Path matching strategy
spring.mvc.pathmatch.matching-strategy=PATH_PATTERN_PARSER
# Options: PATH_PATTERN_PARSER, ANT_PATH_MATCHER
# Content negotiation
spring.mvc.contentnegotiation.favor-parameter=false
spring.mvc.contentnegotiation.parameter-name=format
spring.mvc.contentnegotiation.media-types.json=application/json
spring.mvc.contentnegotiation.media-types.xml=application/xmlConfigure date and time format patterns for request/response binding.
# Date/time format patterns
spring.mvc.format.date=yyyy-MM-dd
spring.mvc.format.time=HH:mm:ss
spring.mvc.format.date-time=yyyy-MM-dd HH:mm:ss
# Locale configuration
spring.web.locale=en_US
spring.web.locale-resolver=ACCEPT_HEADER
# Options: ACCEPT_HEADER, FIXEDConfigure asynchronous request processing timeouts.
# Async request timeout
spring.mvc.async.request-timeout=30sEnable RFC 9457 Problem Details for HTTP APIs error responses.
# RFC 9457 Problem Details support
spring.mvc.problemdetails.enabled=trueConfigure built-in HTTP filters for method override and form content.
# HTTP method override filter (for PUT/DELETE via POST)
spring.mvc.hiddenmethod.filter.enabled=true
# Form content filter (for PUT/PATCH form data)
spring.mvc.formcontent.filter.enabled=trueConfigure HTTP session behavior and cookies.
# Session timeout
server.servlet.session.timeout=30m
# Session cookie configuration
server.servlet.session.cookie.name=JSESSIONID
server.servlet.session.cookie.path=/
server.servlet.session.cookie.domain=
server.servlet.session.cookie.http-only=true
server.servlet.session.cookie.secure=false
server.servlet.session.cookie.max-age=
server.servlet.session.cookie.same-site=STRICT
# Options: STRICT, LAX, NONE
# Session tracking modes
server.servlet.session.tracking-modes=COOKIE,URL
# Options: COOKIE, URL, SSLConfigure request/response character encoding.
# Character encoding
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.enabled=true
server.servlet.encoding.force=false
server.servlet.encoding.force-request=false
server.servlet.encoding.force-response=false
# Locale to charset mappings
server.servlet.encoding.mapping.en=ISO-8859-1
server.servlet.encoding.mapping.ja=Shift_JISConfigure multipart file upload handling.
# Multipart file upload configuration
spring.servlet.multipart.enabled=true
spring.servlet.multipart.location=
spring.servlet.multipart.max-file-size=1MB
spring.servlet.multipart.max-request-size=10MB
spring.servlet.multipart.file-size-threshold=0B
spring.servlet.multipart.resolve-lazily=false
spring.servlet.multipart.strict-servlet-compliance=falseUsage Examples:
# Production file upload settings
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=100MB
spring.servlet.multipart.location=/tmp/uploads
spring.servlet.multipart.resolve-lazily=true
# Development file upload settings
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=20MBConfigure Tomcat embedded server specific settings.
# Tomcat connector settings
server.tomcat.accept-count=100
server.tomcat.max-connections=8192
server.tomcat.max-http-post-size=2MB
server.tomcat.max-swallow-size=2MB
# Thread pool configuration
server.tomcat.threads.max=200
server.tomcat.threads.min-spare=10
# Access logging
server.tomcat.accesslog.enabled=false
server.tomcat.accesslog.directory=logs
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd
server.tomcat.accesslog.pattern=common
server.tomcat.accesslog.prefix=access_log
server.tomcat.accesslog.suffix=.log
# Additional Tomcat settings
server.tomcat.use-relative-redirects=false
server.tomcat.relaxed-path-chars=[]|{}
server.tomcat.relaxed-query-chars=[]|{}^`Customize Spring MVC configuration programmatically.
@Configuration
public class WebConfig implements WebMvcConfigurer {
/**
* Configure path matching options
*/
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseTrailingSlashMatch(true);
configurer.setUseSuffixPatternMatch(false);
}
/**
* Configure content negotiation
*/
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorParameter(true)
.parameterName("mediaType")
.defaultContentType(MediaType.APPLICATION_JSON)
.mediaType("json", MediaType.APPLICATION_JSON)
.mediaType("xml", MediaType.APPLICATION_XML);
}
/**
* Add interceptors
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoggingInterceptor())
.addPathPatterns("/api/**")
.excludePathPatterns("/api/health");
}
/**
* Configure CORS mappings
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.allowCredentials(true);
}
/**
* Add resource handlers for static content
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/uploads/**")
.addResourceLocations("file:./uploads/")
.setCachePeriod(3600);
}
}Customize the embedded web server factory.
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {
return factory -> {
factory.setPort(9090);
factory.setContextPath("/api");
factory.addConnectorCustomizers(connector -> {
connector.setMaxPostSize(50 * 1024 * 1024); // 50MB
});
};
}
@Bean
public WebServerFactoryCustomizer<JettyServletWebServerFactory> jettyCustomizer() {
return factory -> {
factory.setPort(8081);
factory.setContextPath("/app");
};
}// Path matching configuration
public class PathMatchConfigurer {
public PathMatchConfigurer setUseTrailingSlashMatch(boolean trailingSlashMatch);
public PathMatchConfigurer setUseSuffixPatternMatch(boolean suffixPatternMatch);
public PathMatchConfigurer setPathMatcher(PathMatcher pathMatcher);
}
// Content negotiation configuration
public class ContentNegotiationConfigurer {
public ContentNegotiationConfigurer favorParameter(boolean favorParameter);
public ContentNegotiationConfigurer parameterName(String parameterName);
public ContentNegotiationConfigurer mediaType(String extension, MediaType mediaType);
public ContentNegotiationConfigurer defaultContentType(MediaType... defaultContentTypes);
}
// CORS configuration
public class CorsRegistry {
public CorsRegistration addMapping(String pathPattern);
}
public class CorsRegistration {
public CorsRegistration allowedOrigins(String... origins);
public CorsRegistration allowedMethods(String... methods);
public CorsRegistration allowedHeaders(String... headers);
public CorsRegistration allowCredentials(boolean allowCredentials);
public CorsRegistration maxAge(long maxAge);
}Install with Tessl CLI
npx tessl i tessl/maven-org-springframework-boot--spring-boot-starter-web