Mastering Spring Boot Embedded Tomcat: Essential Configuration Tips
This tutorial explains how to customize Spring Boot's embedded Tomcat server by adjusting ports, addresses, error handling, connection limits, SSL settings, and access log options through application.properties, providing clear code examples for each configuration.
1. Overview
Spring Boot web applications include a pre‑configured embedded web server, but you may need to modify the default settings to meet custom requirements.
This guide shows common ways to configure the embedded Tomcat server using application.properties.
2. Common Embedded Tomcat Configurations
2.1 Server address and port
The most frequent change is the port number: server.port=80 If server.port is not set, the default is 8080.
You can also set the IP address the server binds to: server.address=my_custom_ip By default this is 0.0.0.0, allowing connections on all IPv4 addresses; setting it to 127.0.0.1 restricts access to localhost.
2.2 Error handling
Spring Boot provides a default Whitelabel error page, which can be disabled: server.error.whitelabel.enabled=false Custom error path: server.error.path=/user-error Include exception message: server.error.include-exception=true Always show stack trace:
server.error.include-stacktrace=always2.3 Server connections
To control resource usage, you can limit the number of concurrent requests and adjust thread settings: server.tomcat.max-threads=200 Set connection timeout (how long the server waits for a request before closing): server.connection-timeout=5s Maximum HTTP header size: server.max-http-header-size=8KB Maximum request body size: server.tomcat.max-swallow-size=2MB Maximum POST size:
server.tomcat.max-post-size=2MB2.4 SSL
Enable SSL support:
server.ssl.enabled=true
server.ssl.protocol=TLSConfigure keystore password, type, and path:
server.ssl.key-store-password=my_password
server.ssl.key-store-type=keystore_type
server.ssl.key-store=keystoreDefine the key alias:
server.ssl.key-alias=tomcat2.5 Tomcat access logs
Enable access logging and set related parameters:
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.directory=logs
server.tomcat.accesslog.file-date-format=yyyy-MM-dd
server.tomcat.accesslog.prefix=access_log
server.tomcat.accesslog.suffix=.log3. Conclusion
This tutorial covered several common embedded Tomcat configuration options. For a full list of properties, refer to the official Spring Boot application properties documentation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
