CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-springframework-boot--spring-boot-starter-tomcat

Starter for using Tomcat as the embedded servlet container, providing default servlet container functionality for Spring Boot web applications

Pending
Overview
Eval results
Files

Spring Boot Starter Tomcat

Spring Boot Starter Tomcat provides Tomcat embedded servlet container functionality for Spring Boot applications. It serves as the default servlet container starter used by spring-boot-starter-web, enabling developers to create production-ready web applications with embedded Tomcat servers through dependency injection and auto-configuration.

Package Information

  • Package Name: spring-boot-starter-tomcat
  • Package Type: Maven
  • Language: Java
  • Group ID: org.springframework.boot
  • Artifact ID: spring-boot-starter-tomcat
  • Installation: Add dependency to pom.xml or build.gradle

Maven:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <version>2.7.18</version>
</dependency>

Gradle:

implementation 'org.springframework.boot:spring-boot-starter-tomcat:2.7.18'

Core Imports

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer;

Basic Usage

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

@Configuration
public class TomcatConfiguration {
    
    @Bean
    public TomcatConnectorCustomizer connectorCustomizer() {
        return connector -> {
            connector.setPort(8443);
            connector.setSecure(true);
        };
    }
}

Configuration via properties:

# Server configuration
server.port=8080
server.tomcat.basedir=/tmp/tomcat
server.tomcat.threads.max=300
server.tomcat.threads.min-spare=20
server.tomcat.max-connections=10000
server.tomcat.connection-timeout=30s

# Access logging
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=combined

Architecture

Spring Boot Starter Tomcat is built around several key components:

  • Web Server Factories: TomcatServletWebServerFactory and TomcatReactiveWebServerFactory create and configure Tomcat server instances
  • Auto-Configuration: Automatic setup of Tomcat components based on classpath detection and properties
  • Customizers: Functional interfaces (TomcatConnectorCustomizer, TomcatContextCustomizer) for fine-grained server customization
  • Configuration Properties: Extensive property-based configuration through ServerProperties.Tomcat
  • Embedded Dependencies: Includes tomcat-embed-core, tomcat-embed-el, and tomcat-embed-websocket

Capabilities

Web Server Factories

Core factory classes for creating and configuring Tomcat-based web servers. Provides both servlet and reactive web server support with extensive customization options.

public class TomcatServletWebServerFactory extends AbstractServletWebServerFactory 
    implements ConfigurableTomcatWebServerFactory {
    
    public TomcatServletWebServerFactory();
    public TomcatServletWebServerFactory(int port);
    public WebServer getWebServer(ServletContextInitializer... initializers);
}

public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFactory 
    implements ConfigurableTomcatWebServerFactory {
    
    public TomcatReactiveWebServerFactory();
    public WebServer getWebServer(HttpHandler httpHandler);
}

Web Server Factories

Server Customization

Functional interfaces for customizing various aspects of the Tomcat server including connectors, contexts, and protocol handlers.

@FunctionalInterface
public interface TomcatConnectorCustomizer {
    void customize(Connector connector);
}

@FunctionalInterface
public interface TomcatContextCustomizer {
    void customize(Context context);
}

@FunctionalInterface 
public interface TomcatProtocolHandlerCustomizer<T> {
    void customize(T protocolHandler);
}

Server Customization

Configuration Properties

Comprehensive configuration options through Spring Boot's properties system, covering connection settings, threading, access logging, static resources, and SSL.

@ConfigurationProperties(prefix = "server.tomcat")
public static class Tomcat {
    private File basedir;
    private Duration backgroundProcessorDelay = Duration.ofSeconds(10);
    private int maxConnections = 8192;
    private int acceptCount = 100;
    private Duration connectionTimeout;
    private Threads threads = new Threads();
    private Accesslog accesslog = new Accesslog();
    // ... additional properties
}

Configuration Properties

Auto-Configuration

Automatic configuration classes that set up Tomcat components based on classpath detection and application properties.

@AutoConfiguration
@ConditionalOnClass(ServletRequest.class)
@ConditionalOnWebApplication(type = Type.SERVLET)
@EnableConfigurationProperties(ServerProperties.class)
public class ServletWebServerFactoryAutoConfiguration {
    // Auto-configuration beans and customizers
}

Auto-Configuration

Dependencies Provided

The starter automatically includes these embedded Tomcat dependencies:

  • jakarta.annotation:jakarta.annotation-api - Jakarta annotations support
  • org.apache.tomcat.embed:tomcat-embed-core - Core Tomcat embedded functionality
  • org.apache.tomcat.embed:tomcat-embed-el - Expression Language support
  • org.apache.tomcat.embed:tomcat-embed-websocket - WebSocket protocol support

Install with Tessl CLI

npx tessl i tessl/maven-org-springframework-boot--spring-boot-starter-tomcat
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework.boot/spring-boot-starter-tomcat@2.7.x