Book Image

Spring Boot Cookbook

By : Alex Antonov
Book Image

Spring Boot Cookbook

By: Alex Antonov

Overview of this book

Table of Contents (15 chapters)
Spring Boot Cookbook
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

Tuning Tomcat via EmbeddedServletContainerCustomizer


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 an EmbeddedServletContainerCustomizer 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 EmbeddedServletContainerCustomizer to demonstrate the functionality.

How to do it…

  1. Let's say that we want our session to last for one minute. To make this happen, we will add an EmbeddedServletContainerCustomizer bean to our WebConfiguration class with the following content:

    @Bean
    public 
      EmbeddedServletContainerCustomizer
      embeddedServletContainerCustomizer() {
      return new EmbeddedServletContainerCustomizer() {
      ...