0
# Configuration Properties
1
2
Configure Spring Boot web application behavior through application properties and programmatic configuration.
3
4
## Capabilities
5
6
### Server Configuration
7
8
Configure the embedded web server (port, SSL, compression, etc.).
9
10
```properties { .api }
11
# Core server settings
12
server.port=8080
13
server.address=0.0.0.0
14
server.servlet.context-path=/myapp
15
server.servlet.application-display-name=My Application
16
17
# Server headers and limits
18
server.server-header=MyServer/1.0
19
server.max-http-request-header-size=8KB
20
21
# Shutdown behavior
22
server.shutdown=GRACEFUL
23
# Options: GRACEFUL, IMMEDIATE
24
25
# Forward headers strategy (for proxy setups)
26
server.forward-headers-strategy=FRAMEWORK
27
# Options: NATIVE, FRAMEWORK, NONE
28
```
29
30
**Usage Examples:**
31
32
```properties
33
# Production server configuration
34
server.port=8443
35
server.servlet.context-path=/api/v1
36
server.shutdown=GRACEFUL
37
server.forward-headers-strategy=NATIVE
38
39
# Development server configuration
40
server.port=8080
41
server.servlet.context-path=/
42
server.shutdown=IMMEDIATE
43
```
44
45
### SSL/TLS Configuration
46
47
Configure SSL/TLS encryption for HTTPS connections.
48
49
```properties { .api }
50
# SSL/TLS configuration
51
server.ssl.enabled=true
52
server.ssl.key-store=classpath:keystore.p12
53
server.ssl.key-store-password=changeit
54
server.ssl.key-store-type=PKCS12
55
server.ssl.key-alias=tomcat
56
57
# Trust store configuration
58
server.ssl.trust-store=classpath:truststore.p12
59
server.ssl.trust-store-password=changeit
60
server.ssl.trust-store-type=PKCS12
61
62
# SSL protocol and cipher configuration
63
server.ssl.protocol=TLS
64
server.ssl.enabled-protocols=TLSv1.2,TLSv1.3
65
server.ssl.ciphers=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
66
67
# Client certificate authentication
68
server.ssl.client-auth=NEED
69
# Options: NEED, WANT, NONE
70
```
71
72
### HTTP/2 and Compression
73
74
Enable HTTP/2 support and response compression.
75
76
```properties { .api }
77
# HTTP/2 configuration
78
server.http2.enabled=true
79
80
# Response compression
81
server.compression.enabled=true
82
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml
83
server.compression.excluded-user-agents=gozilla,traviata
84
server.compression.min-response-size=2KB
85
```
86
87
### Spring MVC Configuration
88
89
Configure Spring MVC behavior and request handling.
90
91
```properties { .api }
92
# Message codes resolver format
93
spring.mvc.message-codes-resolver-format=PREFIX_ERROR_CODE
94
# Options: PREFIX_ERROR_CODE, POSTFIX_ERROR_CODE
95
96
# Request handling
97
spring.mvc.dispatch-trace-request=false
98
spring.mvc.dispatch-options-request=true
99
spring.mvc.publish-request-handled-events=true
100
spring.mvc.log-request-details=false
101
spring.mvc.log-resolved-exception=false
102
103
# Static resources path pattern
104
spring.mvc.static-path-pattern=/**
105
spring.mvc.webjars-path-pattern=/webjars/**
106
107
# Servlet configuration
108
spring.mvc.servlet.path=/
109
spring.mvc.servlet.load-on-startup=-1
110
111
# View resolution
112
spring.mvc.view.prefix=
113
spring.mvc.view.suffix=
114
115
# Exception handling
116
spring.mvc.throw-exception-if-no-handler-found=false
117
spring.mvc.ignore-default-model-on-redirect=true
118
```
119
120
### Jackson JSON Configuration
121
122
Configure JSON serialization and deserialization behavior.
123
124
```properties { .api }
125
# Jackson JSON configuration
126
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
127
spring.jackson.time-zone=GMT
128
spring.jackson.locale=
129
spring.jackson.joda-date-time-format=
130
spring.jackson.property-naming-strategy=
131
132
# Serialization settings
133
spring.jackson.serialization.indent-output=false
134
spring.jackson.serialization.write-dates-as-timestamps=true
135
spring.jackson.serialization.write-durations-as-timestamps=false
136
spring.jackson.serialization.write-char-arrays-as-json-arrays=false
137
spring.jackson.serialization.write-enums-using-to-string=false
138
spring.jackson.serialization.fail-on-empty-beans=true
139
140
# Deserialization settings
141
spring.jackson.deserialization.fail-on-unknown-properties=true
142
spring.jackson.deserialization.fail-on-null-for-primitives=false
143
spring.jackson.deserialization.fail-on-numbers-for-enums=false
144
spring.jackson.deserialization.accept-single-value-as-array=false
145
spring.jackson.deserialization.unwrap-single-value-arrays=false
146
147
# Parser features
148
spring.jackson.parser.allow-comments=false
149
spring.jackson.parser.allow-yaml-comments=false
150
spring.jackson.parser.allow-unquoted-field-names=false
151
spring.jackson.parser.allow-single-quotes=false
152
153
# Generator features
154
spring.jackson.generator.write-numbers-as-strings=false
155
spring.jackson.generator.escape-non-ascii=false
156
157
# Mapper features
158
spring.jackson.mapper.sort-properties-alphabetically=false
159
spring.jackson.mapper.propagate-transient-marker=false
160
```
161
162
### Path Matching and Content Negotiation
163
164
Configure URL path matching and content type negotiation.
165
166
```properties { .api }
167
# Path matching strategy
168
spring.mvc.pathmatch.matching-strategy=PATH_PATTERN_PARSER
169
# Options: PATH_PATTERN_PARSER, ANT_PATH_MATCHER
170
171
# Content negotiation
172
spring.mvc.contentnegotiation.favor-parameter=false
173
spring.mvc.contentnegotiation.parameter-name=format
174
spring.mvc.contentnegotiation.media-types.json=application/json
175
spring.mvc.contentnegotiation.media-types.xml=application/xml
176
```
177
178
### Date/Time Formatting
179
180
Configure date and time format patterns for request/response binding.
181
182
```properties { .api }
183
# Date/time format patterns
184
spring.mvc.format.date=yyyy-MM-dd
185
spring.mvc.format.time=HH:mm:ss
186
spring.mvc.format.date-time=yyyy-MM-dd HH:mm:ss
187
188
# Locale configuration
189
spring.web.locale=en_US
190
spring.web.locale-resolver=ACCEPT_HEADER
191
# Options: ACCEPT_HEADER, FIXED
192
```
193
194
### Async Request Support
195
196
Configure asynchronous request processing timeouts.
197
198
```properties { .api }
199
# Async request timeout
200
spring.mvc.async.request-timeout=30s
201
```
202
203
### Problem Details Support
204
205
Enable RFC 9457 Problem Details for HTTP APIs error responses.
206
207
```properties { .api }
208
# RFC 9457 Problem Details support
209
spring.mvc.problemdetails.enabled=true
210
```
211
212
### HTTP Filters
213
214
Configure built-in HTTP filters for method override and form content.
215
216
```properties { .api }
217
# HTTP method override filter (for PUT/DELETE via POST)
218
spring.mvc.hiddenmethod.filter.enabled=true
219
220
# Form content filter (for PUT/PATCH form data)
221
spring.mvc.formcontent.filter.enabled=true
222
```
223
224
### Session Configuration
225
226
Configure HTTP session behavior and cookies.
227
228
```properties { .api }
229
# Session timeout
230
server.servlet.session.timeout=30m
231
232
# Session cookie configuration
233
server.servlet.session.cookie.name=JSESSIONID
234
server.servlet.session.cookie.path=/
235
server.servlet.session.cookie.domain=
236
server.servlet.session.cookie.http-only=true
237
server.servlet.session.cookie.secure=false
238
server.servlet.session.cookie.max-age=
239
server.servlet.session.cookie.same-site=STRICT
240
# Options: STRICT, LAX, NONE
241
242
# Session tracking modes
243
server.servlet.session.tracking-modes=COOKIE,URL
244
# Options: COOKIE, URL, SSL
245
```
246
247
### Character Encoding
248
249
Configure request/response character encoding.
250
251
```properties { .api }
252
# Character encoding
253
server.servlet.encoding.charset=UTF-8
254
server.servlet.encoding.enabled=true
255
server.servlet.encoding.force=false
256
server.servlet.encoding.force-request=false
257
server.servlet.encoding.force-response=false
258
259
# Locale to charset mappings
260
server.servlet.encoding.mapping.en=ISO-8859-1
261
server.servlet.encoding.mapping.ja=Shift_JIS
262
```
263
264
### Multipart File Upload
265
266
Configure multipart file upload handling.
267
268
```properties { .api }
269
# Multipart file upload configuration
270
spring.servlet.multipart.enabled=true
271
spring.servlet.multipart.location=
272
spring.servlet.multipart.max-file-size=1MB
273
spring.servlet.multipart.max-request-size=10MB
274
spring.servlet.multipart.file-size-threshold=0B
275
spring.servlet.multipart.resolve-lazily=false
276
spring.servlet.multipart.strict-servlet-compliance=false
277
```
278
279
**Usage Examples:**
280
281
```properties
282
# Production file upload settings
283
spring.servlet.multipart.enabled=true
284
spring.servlet.multipart.max-file-size=50MB
285
spring.servlet.multipart.max-request-size=100MB
286
spring.servlet.multipart.location=/tmp/uploads
287
spring.servlet.multipart.resolve-lazily=true
288
289
# Development file upload settings
290
spring.servlet.multipart.enabled=true
291
spring.servlet.multipart.max-file-size=10MB
292
spring.servlet.multipart.max-request-size=20MB
293
```
294
295
### Tomcat-Specific Configuration
296
297
Configure Tomcat embedded server specific settings.
298
299
```properties { .api }
300
# Tomcat connector settings
301
server.tomcat.accept-count=100
302
server.tomcat.max-connections=8192
303
server.tomcat.max-http-post-size=2MB
304
server.tomcat.max-swallow-size=2MB
305
306
# Thread pool configuration
307
server.tomcat.threads.max=200
308
server.tomcat.threads.min-spare=10
309
310
# Access logging
311
server.tomcat.accesslog.enabled=false
312
server.tomcat.accesslog.directory=logs
313
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd
314
server.tomcat.accesslog.pattern=common
315
server.tomcat.accesslog.prefix=access_log
316
server.tomcat.accesslog.suffix=.log
317
318
# Additional Tomcat settings
319
server.tomcat.use-relative-redirects=false
320
server.tomcat.relaxed-path-chars=[]|{}
321
server.tomcat.relaxed-query-chars=[]|{}^`
322
```
323
324
## Programmatic Configuration
325
326
### WebMvcConfigurer
327
328
Customize Spring MVC configuration programmatically.
329
330
```java { .api }
331
@Configuration
332
public class WebConfig implements WebMvcConfigurer {
333
334
/**
335
* Configure path matching options
336
*/
337
@Override
338
public void configurePathMatch(PathMatchConfigurer configurer) {
339
configurer.setUseTrailingSlashMatch(true);
340
configurer.setUseSuffixPatternMatch(false);
341
}
342
343
/**
344
* Configure content negotiation
345
*/
346
@Override
347
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
348
configurer.favorParameter(true)
349
.parameterName("mediaType")
350
.defaultContentType(MediaType.APPLICATION_JSON)
351
.mediaType("json", MediaType.APPLICATION_JSON)
352
.mediaType("xml", MediaType.APPLICATION_XML);
353
}
354
355
/**
356
* Add interceptors
357
*/
358
@Override
359
public void addInterceptors(InterceptorRegistry registry) {
360
registry.addInterceptor(new LoggingInterceptor())
361
.addPathPatterns("/api/**")
362
.excludePathPatterns("/api/health");
363
}
364
365
/**
366
* Configure CORS mappings
367
*/
368
@Override
369
public void addCorsMappings(CorsRegistry registry) {
370
registry.addMapping("/api/**")
371
.allowedOrigins("http://localhost:3000")
372
.allowedMethods("GET", "POST", "PUT", "DELETE")
373
.allowedHeaders("*")
374
.allowCredentials(true);
375
}
376
377
/**
378
* Add resource handlers for static content
379
*/
380
@Override
381
public void addResourceHandlers(ResourceHandlerRegistry registry) {
382
registry.addResourceHandler("/uploads/**")
383
.addResourceLocations("file:./uploads/")
384
.setCachePeriod(3600);
385
}
386
}
387
```
388
389
### WebServerFactoryCustomizer
390
391
Customize the embedded web server factory.
392
393
```java { .api }
394
@Bean
395
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomizer() {
396
return factory -> {
397
factory.setPort(9090);
398
factory.setContextPath("/api");
399
factory.addConnectorCustomizers(connector -> {
400
connector.setMaxPostSize(50 * 1024 * 1024); // 50MB
401
});
402
};
403
}
404
405
@Bean
406
public WebServerFactoryCustomizer<JettyServletWebServerFactory> jettyCustomizer() {
407
return factory -> {
408
factory.setPort(8081);
409
factory.setContextPath("/app");
410
};
411
}
412
```
413
414
## Configuration Classes
415
416
```java { .api }
417
// Path matching configuration
418
public class PathMatchConfigurer {
419
public PathMatchConfigurer setUseTrailingSlashMatch(boolean trailingSlashMatch);
420
public PathMatchConfigurer setUseSuffixPatternMatch(boolean suffixPatternMatch);
421
public PathMatchConfigurer setPathMatcher(PathMatcher pathMatcher);
422
}
423
424
// Content negotiation configuration
425
public class ContentNegotiationConfigurer {
426
public ContentNegotiationConfigurer favorParameter(boolean favorParameter);
427
public ContentNegotiationConfigurer parameterName(String parameterName);
428
public ContentNegotiationConfigurer mediaType(String extension, MediaType mediaType);
429
public ContentNegotiationConfigurer defaultContentType(MediaType... defaultContentTypes);
430
}
431
432
// CORS configuration
433
public class CorsRegistry {
434
public CorsRegistration addMapping(String pathPattern);
435
}
436
437
public class CorsRegistration {
438
public CorsRegistration allowedOrigins(String... origins);
439
public CorsRegistration allowedMethods(String... methods);
440
public CorsRegistration allowedHeaders(String... headers);
441
public CorsRegistration allowCredentials(boolean allowCredentials);
442
public CorsRegistration maxAge(long maxAge);
443
}
444
```