0
# Configuration Properties
1
2
Comprehensive configuration options through Spring Boot's properties system, covering connection settings, threading, access logging, static resources, SSL, and performance tuning. These properties provide declarative configuration without requiring custom code.
3
4
## Capabilities
5
6
### ServerProperties.Tomcat
7
8
Main configuration class for all Tomcat-specific properties under the `server.tomcat.*` prefix.
9
10
```java { .api }
11
/**
12
* Tomcat-specific server properties configuration
13
*/
14
@ConfigurationProperties(prefix = "server.tomcat")
15
public static class Tomcat {
16
17
/** Tomcat base directory for temporary files and work directories */
18
private File basedir;
19
20
/** Background processor delay for maintenance tasks (default: 10s) */
21
private Duration backgroundProcessorDelay = Duration.ofSeconds(10);
22
23
/** Maximum number of connections server will accept and process (default: 8192) */
24
private int maxConnections = 8192;
25
26
/** Maximum queue length for incoming connections (default: 100) */
27
private int acceptCount = 100;
28
29
/** Processor cache size for request processing (default: 200) */
30
private int processorCache = 200;
31
32
/** Connection timeout for client connections */
33
private Duration connectionTimeout;
34
35
/** Keep-alive timeout for persistent connections */
36
private Duration keepAliveTimeout;
37
38
/** Maximum number of HTTP requests per keep-alive connection (default: 100) */
39
private int maxKeepAliveRequests = 100;
40
41
/** Maximum size of HTTP form post data (default: 2MB) */
42
private DataSize maxHttpFormPostSize = DataSize.ofMegabytes(2);
43
44
/** Maximum size of request data to swallow (default: 2MB) */
45
private DataSize maxSwallowSize = DataSize.ofMegabytes(2);
46
47
/** Character encoding for URI decoding (default: UTF-8) */
48
private Charset uriEncoding = StandardCharsets.UTF_8;
49
50
/** Characters allowed in URL paths beyond standard safe characters */
51
private List<Character> relaxedPathChars = new ArrayList<>();
52
53
/** Characters allowed in URL query strings beyond standard safe characters */
54
private List<Character> relaxedQueryChars = new ArrayList<>();
55
56
/** Whether to redirect requests with context root (default: true) */
57
private Boolean redirectContextRoot = true;
58
59
/** Whether to use relative redirects (default: false) */
60
private boolean useRelativeRedirects = false;
61
62
/** Additional patterns for TLD files to skip during scanning */
63
private List<String> additionalTldSkipPatterns = new ArrayList<>();
64
65
/** Thread pool configuration */
66
private final Threads threads = new Threads();
67
68
/** Access log configuration */
69
private final Accesslog accesslog = new Accesslog();
70
71
/** Static resource configuration */
72
private final Resource resource = new Resource();
73
74
/** MBean registry configuration */
75
private final Mbeanregistry mbeanregistry = new Mbeanregistry();
76
77
/** Remote IP valve configuration */
78
private final Remoteip remoteip = new Remoteip();
79
}
80
```
81
82
### Thread Configuration
83
84
Configuration for Tomcat's thread pool under `server.tomcat.threads.*` prefix.
85
86
```java { .api }
87
/**
88
* Thread pool configuration for Tomcat connectors
89
*/
90
public static class Threads {
91
92
/** Maximum number of worker threads (default: 200) */
93
private int max = 200;
94
95
/** Minimum number of spare worker threads (default: 10) */
96
private int minSpare = 10;
97
}
98
```
99
100
**Configuration Example:**
101
```properties
102
server.tomcat.threads.max=300
103
server.tomcat.threads.min-spare=20
104
```
105
106
### Access Log Configuration
107
108
Configuration for Tomcat access logging under `server.tomcat.accesslog.*` prefix.
109
110
```java { .api }
111
/**
112
* Access log configuration for request logging
113
*/
114
public static class Accesslog {
115
116
/** Whether to enable access logging (default: false) */
117
private boolean enabled = false;
118
119
/** Access log pattern format (default: "common") */
120
private String pattern = "common";
121
122
/** Directory for access log files (default: "logs") */
123
private String directory = "logs";
124
125
/** Prefix for access log file names (default: "access_log") */
126
private String prefix = "access_log";
127
128
/** Suffix for access log file names (default: ".log") */
129
private String suffix = ".log";
130
131
/** Character encoding for log files */
132
private String encoding;
133
134
/** Whether to rotate log files daily (default: true) */
135
private boolean rotate = true;
136
137
/** Number of days to retain log files (-1 for unlimited, default: -1) */
138
private int maxDays = -1;
139
140
/** Whether to buffer log output for performance (default: true) */
141
private boolean buffered = true;
142
}
143
```
144
145
**Configuration Example:**
146
```properties
147
server.tomcat.accesslog.enabled=true
148
server.tomcat.accesslog.pattern=combined
149
server.tomcat.accesslog.directory=/var/log/tomcat
150
server.tomcat.accesslog.max-days=30
151
server.tomcat.accesslog.buffered=false
152
```
153
154
### Static Resource Configuration
155
156
Configuration for static resource handling under `server.tomcat.resource.*` prefix.
157
158
```java { .api }
159
/**
160
* Static resource configuration for caching and optimization
161
*/
162
public static class Resource {
163
164
/** Whether to allow caching of static resources (default: true) */
165
private boolean allowCaching = true;
166
167
/** Time-to-live for cached static resources */
168
private Duration cacheTtl;
169
}
170
```
171
172
**Configuration Example:**
173
```properties
174
server.tomcat.resource.allow-caching=true
175
server.tomcat.resource.cache-ttl=24h
176
```
177
178
### MBean Registry Configuration
179
180
Configuration for Tomcat's MBean registry under `server.tomcat.mbeanregistry.*` prefix.
181
182
```java { .api }
183
/**
184
* MBean registry configuration for JMX management
185
*/
186
public static class Mbeanregistry {
187
188
/** Whether to enable MBean registry (default: false) */
189
private boolean enabled = false;
190
}
191
```
192
193
### Remote IP Valve Configuration
194
195
Configuration for X-Forwarded headers processing under `server.tomcat.remoteip.*` prefix.
196
197
```java { .api }
198
/**
199
* Remote IP valve configuration for proxy setups
200
*/
201
public static class Remoteip {
202
203
/** Regular expression for internal proxy IP addresses */
204
private String internalProxies;
205
206
/** Header name containing the protocol (HTTP/HTTPS) */
207
private String protocolHeader;
208
209
/** Value indicating HTTPS protocol (default: "https") */
210
private String protocolHeaderHttpsValue = "https";
211
212
/** Header name containing the original host (default: "X-Forwarded-Host") */
213
private String hostHeader = "X-Forwarded-Host";
214
215
/** Header name containing the original port (default: "X-Forwarded-Port") */
216
private String portHeader = "X-Forwarded-Port";
217
218
/** Header name containing the remote IP address */
219
private String remoteIpHeader;
220
}
221
```
222
223
**Configuration Example:**
224
```properties
225
server.tomcat.remoteip.protocol-header=X-Forwarded-Proto
226
server.tomcat.remoteip.protocol-header-https-value=https
227
server.tomcat.remoteip.remote-ip-header=X-Forwarded-For
228
server.tomcat.remoteip.internal-proxies=10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|192\\.168\\.\\d{1,3}\\.\\d{1,3}
229
```
230
231
## Complete Configuration Examples
232
233
### Basic Web Application
234
235
```properties
236
# Basic server configuration
237
server.port=8080
238
server.servlet.context-path=/myapp
239
240
# Tomcat-specific settings
241
server.tomcat.basedir=/tmp/tomcat
242
server.tomcat.uri-encoding=UTF-8
243
server.tomcat.max-connections=5000
244
server.tomcat.accept-count=100
245
server.tomcat.connection-timeout=20s
246
247
# Thread pool
248
server.tomcat.threads.max=150
249
server.tomcat.threads.min-spare=10
250
251
# Access logging
252
server.tomcat.accesslog.enabled=true
253
server.tomcat.accesslog.pattern=common
254
server.tomcat.accesslog.directory=logs
255
```
256
257
### High-Performance Production Setup
258
259
```properties
260
# Performance-oriented configuration
261
server.tomcat.max-connections=10000
262
server.tomcat.accept-count=200
263
server.tomcat.connection-timeout=30s
264
server.tomcat.keep-alive-timeout=15s
265
server.tomcat.max-keep-alive-requests=100
266
267
# Thread pool for high throughput
268
server.tomcat.threads.max=300
269
server.tomcat.threads.min-spare=50
270
271
# Request size limits
272
server.tomcat.max-http-form-post-size=10MB
273
server.tomcat.max-swallow-size=10MB
274
275
# Static resource optimization
276
server.tomcat.resource.allow-caching=true
277
server.tomcat.resource.cache-ttl=24h
278
279
# Access logging for production
280
server.tomcat.accesslog.enabled=true
281
server.tomcat.accesslog.pattern=combined
282
server.tomcat.accesslog.directory=/var/log/tomcat
283
server.tomcat.accesslog.max-days=30
284
server.tomcat.accesslog.buffered=true
285
```
286
287
### Behind Load Balancer/Proxy
288
289
```properties
290
# Proxy configuration
291
server.tomcat.remoteip.protocol-header=X-Forwarded-Proto
292
server.tomcat.remoteip.protocol-header-https-value=https
293
server.tomcat.remoteip.remote-ip-header=X-Forwarded-For
294
server.tomcat.remoteip.host-header=X-Forwarded-Host
295
server.tomcat.remoteip.port-header=X-Forwarded-Port
296
server.tomcat.remoteip.internal-proxies=10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|192\\.168\\.\\d{1,3}\\.\\d{1,3}|172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}
297
298
# Disable direct redirect handling (let proxy handle)
299
server.tomcat.redirect-context-root=false
300
server.tomcat.use-relative-redirects=true
301
302
# Connection settings for proxy environment
303
server.tomcat.connection-timeout=60s
304
server.tomcat.keep-alive-timeout=30s
305
```
306
307
### Development Environment
308
309
```properties
310
# Development-friendly settings
311
server.port=8080
312
server.tomcat.basedir=./tomcat-temp
313
314
# Relaxed timeout for debugging
315
server.tomcat.connection-timeout=300s
316
317
# Smaller thread pool for development
318
server.tomcat.threads.max=50
319
server.tomcat.threads.min-spare=5
320
321
# Enable access logging for debugging
322
server.tomcat.accesslog.enabled=true
323
server.tomcat.accesslog.pattern=combined
324
325
# Allow relaxed path characters for development
326
server.tomcat.relaxed-path-chars=<,>,[,\\,],^,`,{,|,}
327
server.tomcat.relaxed-query-chars=<,>,[,\\,],^,`,{,|,}
328
```
329
330
## Property Validation and Defaults
331
332
Properties are validated at startup and provide sensible defaults:
333
334
- **Numeric values**: Must be positive integers where applicable
335
- **Duration values**: Support standard formats (30s, 5m, 1h, etc.)
336
- **DataSize values**: Support standard formats (1KB, 2MB, 1GB, etc.)
337
- **File paths**: Automatically created if they don't exist
338
- **Character sets**: Must be valid Java charset names
339
- **Patterns**: Validated as proper regular expressions where applicable
340
341
## Environment-Specific Configuration
342
343
Properties can be overridden per environment using Spring Boot profiles:
344
345
**application-dev.properties:**
346
```properties
347
server.tomcat.threads.max=50
348
server.tomcat.accesslog.enabled=true
349
```
350
351
**application-prod.properties:**
352
```properties
353
server.tomcat.threads.max=300
354
server.tomcat.max-connections=10000
355
server.tomcat.accesslog.enabled=true
356
server.tomcat.accesslog.max-days=90
357
```