1. Overview

Spring Boot web applications include a pre-configured, embedded web server by default. In some situations though, we'd like to modify the default configuration to meet custom requirements.

In this tutorial, we'll look at a few common use cases for configuring the Tomcat embedded server through the application.properties file.

2. Common Embedded Tomcat Configurations

2.1. Server Address and Port

The most common configuration we may wish to change is the port number:


If we don't provide the server.port parameter it's set to 8080 by default.

In some cases, we may wish to set a network address to which the server should bind. In other words, we define an IP address where our server will listen:


By default, the value is set to which allows connection via all IPv4 addresses. Setting another value, for example, localhost – – will make the server more selective.

2.2. Error Handling

By default, Spring Boot provides a standard error web page. This page is called the Whitelabel. It's enabled by default but if we don't want to display any error information we can  disable it:


The default path to a Whitelabel is /error. We can customize it by setting the server.error.path parameter:


We can also set properties that will determine which information about the error is presented. For example, we can include the error message and the stack trace:


Our tutorials Exception Message Handling for REST and Customize Whitelabel Error Page explain more about handling errors in Spring Boot.

2.3. Server Connections

When running on a low resource container we might like to decrease the CPU and memory load. One way of doing that is to limit the number of simultaneous requests that can be handled by our application. Conversely, we can increase this value to use more available resources to get better performance.

In Spring Boot, we can define the maximum amount of Tomcat worker threads:


When configuring a web server, it also might be useful to set the server connection timeout. This represents the maximum amount of time the server will wait for the client to make their request after connecting before the connection is closed:


We can also define the maximum size of a request header:


The maximum size of a request body:


Or a maximum size of the whole post request:


2.4. SSL

To enable SSL support in our Spring Boot application we need to set the server.ssl.enabled property to true and define an SSL protocol:


We should also configure the password, type, and path to the key store that holds the certificate:


And we must also define the alias that identifies our key in the key store:


For more information about SSL configuration, visit our HTTPS using self-signed certificate in Spring Boot article.

2.5. Tomcat Server Access Logs

Tomcat access logs are very useful when trying to measure page hit counts, user session activity, and so on.

To enable access logs, simply set:


We should also configure other parameters such as directory name, prefix, suffix, and date format appended to log files:


3. Conclusion

In this tutorial, we've learned a few common Tomcat embedded server configurations. To view more possible configurations, please visit the official Spring Boot application properties docs page.

As always, the source code for these examples is available over on GitHub.

Generic bottom

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

Comments are closed on this article!