or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

http-client.mdindex.mdreactive-web-server.mdserver-configuration.mdservlet-web-server.mdwebsocket-support.md
tile.json

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

Starter for using Jetty as the embedded servlet container in Spring Boot applications

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework.boot/spring-boot-starter-jetty@3.5.x

To install, run

npx @tessl/cli install tessl/maven-org-springframework-boot--spring-boot-starter-jetty@3.5.0

index.mddocs/

Spring Boot Starter Jetty

Spring Boot Starter Jetty provides Eclipse Jetty as an embedded servlet container for Spring Boot applications. It serves as a drop-in replacement for the default Tomcat container, offering advanced WebSocket support, custom server configurations, and specific performance characteristics that Jetty provides over other embedded containers.

Package Information

  • Package Name: spring-boot-starter-jetty
  • Package Type: maven
  • Language: Java
  • Installation: Add to Maven dependencies or replace spring-boot-starter-web with spring-boot-starter-jetty
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

For Gradle:

implementation 'org.springframework.boot:spring-boot-starter-jetty'

Core Imports

import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory;
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
import org.springframework.boot.web.embedded.jetty.ConfigurableJettyWebServerFactory;

Basic Usage

Replacing Tomcat with Jetty

// In your main application or configuration class
@SpringBootApplication
public class JettyApplication {
    public static void main(String[] args) {
        SpringApplication.run(JettyApplication.class, args);
    }
}
<!-- Exclude Tomcat and include Jetty -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

Custom Jetty Configuration

@Configuration
public class JettyConfig {
    
    @Bean
    public JettyServletWebServerFactory jettyWebServerFactory() {
        JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
        factory.setPort(8080);
        factory.addServerCustomizers(new JettyServerCustomizer() {
            @Override
            public void customize(Server server) {
                // Custom server configuration
            }
        });
        return factory;
    }
}

Architecture

Spring Boot Starter Jetty integrates with Spring Boot's auto-configuration system through several key components:

  • Web Server Factories: Create and configure Jetty server instances for both servlet and reactive applications
  • Auto-Configuration: Automatic detection and configuration based on classpath presence
  • Customizers: Extension points for modifying server behavior and configuration
  • Properties Support: Integration with Spring Boot's externalized configuration system
  • Actuator Integration: Built-in metrics and monitoring support for Jetty servers

Capabilities

Servlet Web Server

Core servlet container functionality using Jetty as the embedded server. Provides complete servlet container capabilities with Spring Boot integration.

public class JettyServletWebServerFactory 
    extends AbstractServletWebServerFactory 
    implements ConfigurableJettyWebServerFactory, ResourceLoaderAware {
    
    public JettyServletWebServerFactory();
    public JettyServletWebServerFactory(int port);
    public JettyServletWebServerFactory(String contextPath, int port);
    
    public WebServer getWebServer(ServletContextInitializer... initializers);
    public void addServerCustomizers(JettyServerCustomizer... customizers);
    public void setMaxConnections(int maxConnections);
    public void setResourceLoader(ResourceLoader resourceLoader);
    public Collection<JettyServerCustomizer> getServerCustomizers();
}

Servlet Web Server

Reactive Web Server

Reactive web server implementation using Jetty for WebFlux applications. Provides non-blocking, reactive HTTP server capabilities.

public class JettyReactiveWebServerFactory 
    extends AbstractReactiveWebServerFactory 
    implements ConfigurableJettyWebServerFactory {
    
    public JettyReactiveWebServerFactory();
    public JettyReactiveWebServerFactory(int port);
    
    public WebServer getWebServer(HttpHandler httpHandler);
    public void addServerCustomizers(JettyServerCustomizer... customizers);
    public void setMaxConnections(int maxConnections);
    public void setResourceFactory(JettyResourceFactory resourceFactory);
    public Collection<JettyServerCustomizer> getServerCustomizers();
}

Reactive Web Server

Server Configuration

Comprehensive server configuration and customization options including SSL, threading, connectors, and advanced Jetty features.

public interface JettyServerCustomizer {
    void customize(Server server);
}

public interface ConfigurableJettyWebServerFactory extends ConfigurableWebServerFactory {
    void addServerCustomizers(JettyServerCustomizer... customizers);
    void setUseForwardHeaders(boolean useForwardHeaders);
    void setAcceptors(int acceptors);
    void setSelectors(int selectors);
    void setMaxConnections(int maxConnections);
    void setThreadPool(ThreadPool threadPool);
}

Server Configuration

WebSocket Support

WebSocket capabilities for both servlet and reactive applications with Jakarta WebSocket API support.

public class JettyWebSocketServletWebServerCustomizer implements WebServerFactoryCustomizer<JettyServletWebServerFactory> {
    public void customize(JettyServletWebServerFactory factory);
}

public class JettyWebSocketReactiveWebServerCustomizer implements WebServerFactoryCustomizer<JettyReactiveWebServerFactory> {
    public void customize(JettyReactiveWebServerFactory factory);
}

WebSocket Support

HTTP Client

HTTP client builders for creating Jetty-based HTTP clients in Spring Boot applications.

public class JettyClientHttpRequestFactoryBuilder 
    implements ClientHttpRequestFactoryBuilder<JettyClientHttpRequestFactory> {
    
    public JettyClientHttpRequestFactoryBuilder();
    public JettyClientHttpRequestFactoryBuilder httpClient(HttpClient httpClient);
    public JettyClientHttpRequestFactoryBuilder connectTimeout(Duration connectTimeout);
    public JettyClientHttpRequestFactoryBuilder readTimeout(Duration readTimeout);
    public JettyClientHttpRequestFactory build();
}

public class JettyHttpClientBuilder {
    public JettyHttpClientBuilder();
    public JettyHttpClientBuilder sslContextFactory(SslContextFactory.Client sslContextFactory);
    public JettyHttpClientBuilder connectTimeout(Duration connectTimeout);
    public JettyHttpClientBuilder idleTimeout(Duration idleTimeout);
    public HttpClient build();
}

HTTP Client

Auto-Configuration

Spring Boot auto-configuration classes that automatically configure Jetty based on application properties and classpath detection.

public class JettyWebServerFactoryCustomizer 
    implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> {
    
    public JettyWebServerFactoryCustomizer(ServerProperties serverProperties, 
                                         ObjectProvider<JettyThreadPool> threadPool);
    public void customize(ConfigurableJettyWebServerFactory factory);
}

public class JettyVirtualThreadsWebServerFactoryCustomizer 
    implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> {
    
    public JettyVirtualThreadsWebServerFactoryCustomizer();
    public void customize(ConfigurableJettyWebServerFactory factory);
}

public class JettyThreadPool implements ThreadPool {
    public static JettyThreadPool create(ServerProperties.Jetty jettyProperties);
    public JettyThreadPool();
    public JettyThreadPool(int maxThreads, int minThreads, int idleTimeout);
    public void setMaxThreads(int maxThreads);
    public void setMinThreads(int minThreads);
    public void setIdleTimeout(int idleTimeout);
    public void execute(Runnable job);
    public boolean isLowOnThreads();
}

Types

Core Server Types

public class JettyWebServer implements WebServer {
    public JettyWebServer(Server server);
    public JettyWebServer(Server server, boolean autoStart);
    public void start() throws WebServerException;
    public void stop() throws WebServerException;
    public int getPort();
    public Server getServer();
    public void shutDownGracefully(GracefulShutdownCallback callback);
    public void destroy();
}

public class JettyEmbeddedWebAppContext extends WebAppContext {
    public JettyEmbeddedWebAppContext();
    public JettyEmbeddedWebAppContext(String webApp, String contextPath);
    public void setTempDirectory(File tempDirectory);
    public void setParentLoaderPriority(boolean parentLoaderPriority);
    public void setSessionTimeout(int sessionTimeout);
}

public class JettyEmbeddedErrorHandler extends ErrorHandler {
    public JettyEmbeddedErrorHandler();
    public void handle(String target, Request baseRequest, 
                      HttpServletRequest request, HttpServletResponse response);
    public void setShowServlet(boolean showServlet);
    public void setShowStacks(boolean showStacks);
}

public class GracefulShutdown {
    public GracefulShutdown();
    public void shutDownGracefully(GracefulShutdownCallback callback);
    public void setTimeout(Duration timeout);
}

Resource Management Types

public class JettyResourceFactory implements DisposableBean, InitializingBean {
    public JettyResourceFactory();
    public HttpClient getHttpClient();
    public Executor getExecutor();
    public Scheduler getScheduler();
    public ByteBufferPool getByteBufferPool();
    public void setThreadPool(ThreadPool threadPool);
    public void setExecutor(Executor executor);
    public void setScheduler(Scheduler scheduler);
    public void setByteBufferPool(ByteBufferPool byteBufferPool);
    public void afterPropertiesSet() throws Exception;
    public void destroy() throws Exception;
}

Customizer Types

public class SslServerCustomizer implements JettyServerCustomizer {
    public SslServerCustomizer();
    public void customize(Server server);
    public void configureSslContextFactory(SslContextFactory.Server sslContextFactory);
    public void setIncludeProtocols(String... protocols);
    public void setIncludeCipherSuites(String... cipherSuites);
    public void setNeedClientAuth(boolean needClientAuth);
    public void setWantClientAuth(boolean wantClientAuth);
}

public class ForwardHeadersCustomizer implements JettyServerCustomizer {
    public ForwardHeadersCustomizer();
    public void customize(Server server);
    public void setTrustedProxies(String... trustedProxies);
    public void setForwardedHostHeader(String forwardedHostHeader);
    public void setForwardedPortHeader(String forwardedPortHeader);
    public void setForwardedProtoHeader(String forwardedProtoHeader);
}

Configuration Properties

Jetty-specific configuration properties available through Spring Boot's server.jetty.* namespace:

server:
  jetty:
    acceptors: 2                    # Number of acceptor threads
    selectors: 4                    # Number of selector threads  
    max-http-post-size: 10MB        # Maximum HTTP POST size
    threads:
      max: 200                      # Maximum thread pool size
      min: 10                       # Minimum thread pool size
      idle-timeout: 60s             # Thread idle timeout
    connection:
      idle-timeout: 30s             # Connection idle timeout
      accept-queue-size: 128        # Accept queue size