Spring Boot provides a number of features that can be used to customize the embedded Tomcat configuration. In this post, we'll take a look at a few of the most important configuration options.
The first thing you might want to do is change the HTTP port that Tomcat is running on. By default, Tomcat will run on port 8080, but you can change this by setting the server.port
property in your application.properties file:
server.port=8081
Another common customization is to change the session timeout. By default, Tomcat will use a 30-minute session timeout, but you can change this by setting the server.session-timeout
property:
server.session-timeout=1
Tomcat will also create an access log that contains information about all of the requests that are made to the server. By default, this log is located in the logs
directory, but you can change the location by setting the server.tomcat.accesslog.directory
property:
server.tomcat.accesslog.directory=/var/log/tomcat
By default, Tomcat will use the ISO-8859-1 character set for URI encoding. However, you can change this by setting the server.tomcat.uri-encoding
property:
server.tomcat.uri-encoding=UTF-8
Tomcat uses a connector to receive requests and send responses. By default, Tomcat will use the AJP connector, but you can change this by setting the server.tomcat.protocol-header
property:
server.tomcat.protocol-header=org.apache.coyote.http11.Http11NioProtocol
The context path is the path that is used to access your application. By default, this is set to /
, but you can change it by setting the server.context-path
property:
server.context-path=/myapp
Tomcat also supports SSL for secure communications. To configure SSL, you will need to set the server.ssl.key-store
, server.ssl.key-store-password
, server.ssl.key-alias
, and server.ssl.key-alias-password
properties. For more information about configuring SSL in Tomcat, see the Tomcat SSL Configuration How-To.
In this post, we've looked at a few of the most important ways to customize the embedded Tomcat configuration in Spring Boot. By changing a few simple properties, you can change the way Tomcat runs to better suit your needs.