Tuning Tomcat via ServletWebServerFactory
Spring Boot exposes many of the server properties that can be used to configure things such as PORT, SSL, and others by simply setting the values in application.properties. However, if we need to do any more complex tuning, Spring Boot provides us with a ServletWebServerFactory interface to programmatically define our configuration.
Even though the session timeout can be easily configured by setting the server.session.timeout property in application.properties to our desired value in seconds, we will do it using ServletWebServerFactory to demonstrate how it is done.
How to do it...
- Let's say that we want our session to be for one minute. To make this happen, we will ad a
ServletWebServerFactorybean to ourWebConfigurationclass with the following content:
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat =
new TomcatServletWebServerFactory();
tomcat.getSession().setTimeout(Duration.ofMinutes...