How to configure Jetty in spring-boot easily?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Spring Boot makes Jetty configuration easier than it used to be because the embedded server is just another starter dependency. In most cases, "configure Jetty" means three separate tasks: swap out Tomcat, apply server settings, and optionally customize Jetty-specific internals. Once those are separated, the setup is straightforward.
Replace Tomcat With Jetty
If you start from spring-boot-starter-web, Tomcat is included by default. Exclude it and add Jetty instead.
After that, Boot will start Jetty automatically because it detects the server on the classpath.
Start With Standard Server Properties
Many server settings are not Jetty-specific at all. They come from Spring Boot’s standard server properties.
These work regardless of the embedded server implementation and should be your first stop for basic configuration.
Add Jetty-Specific Thread Settings
When you need Jetty tuning, Spring Boot exposes several Jetty-specific properties. Thread configuration is a common example.
These values affect the server thread pool. They should be chosen based on expected concurrency, blocking behavior, and the rest of the deployment stack, not copied blindly from internet snippets.
Customize Jetty Programmatically
For settings that are easier to express in code, define a JettyServletWebServerFactory bean.
This pattern is useful when you need handlers, connectors, request logging, or other server-level adjustments that do not fit neatly into properties.
Keep The Change Small At First
A common mistake is trying to tune every Jetty knob before the app has even been measured. A good migration path is:
- replace Tomcat with Jetty,
- keep default settings,
- confirm the app starts and passes tests,
- tune only the settings tied to a measured bottleneck.
That keeps the change understandable and reduces the chance of mixing server migration bugs with tuning mistakes.
Know What Jetty Does Not Change
Switching to Jetty does not automatically fix application-level problems such as:
- slow database queries,
- blocking controllers,
- oversized thread pools elsewhere,
- memory leaks,
- poor connection management to downstream systems.
Jetty can be a better fit for some workloads, but the embedded server is only one part of the runtime profile.
A Minimal Gradle Equivalent
If you use Gradle instead of Maven, the dependency change is similar.
The rest of the Spring Boot configuration patterns stay the same.
Common Pitfalls
- Adding Jetty without excluding Tomcat and then wondering which server Boot will use.
- Tuning Jetty thread counts without understanding whether the app is blocking or non-blocking.
- Moving Jetty-specific code into the app before verifying that standard Boot properties are enough.
- Assuming a server swap alone will solve throughput or latency issues.
- Making too many migration changes at once instead of isolating the server change.
Summary
- Replace Tomcat with
spring-boot-starter-jettyand let Spring Boot auto-configure the server. - Use standard
server.*properties first for basic setup. - Add Jetty-specific properties only when you actually need them.
- Use
JettyServletWebServerFactoryfor programmatic server customization. - Measure before tuning so Jetty configuration stays tied to a real performance goal.

