Spring Boot
Tomcat
Embedded Servlet Container
Error Resolution
Java Development

Spring boot Unable to start embedded Tomcat servlet container

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

"Unable to start embedded Tomcat servlet container" is a wrapper error, not the root cause. Tomcat failed during startup, but the real reason is almost always lower in the stack trace: port conflict, broken bean initialization, invalid servlet configuration, or a missing dependency.

The fastest way to solve it is to ignore the headline message and read the first meaningful exception beneath it. Tomcat is often just the messenger.

Start with the Real Cause

When Spring Boot fails at startup, the console usually shows a chain of exceptions. The useful one is often one or two levels below the top-level Tomcat error.

Typical examples:

  • 'PortInUseException'
  • 'BeanCreationException'
  • 'ApplicationContextException'
  • 'ClassNotFoundException'
  • 'NoSuchMethodError'

Your first task is to identify which of those actually caused the container bootstrap to fail.

Common Causes

Port Already in Use

If another service is already listening on port 8080, embedded Tomcat cannot bind.

properties
server.port=8081

Or inspect the port owner at the OS level before changing configuration.

Dependency or Classpath Conflict

Mixing incompatible versions of Spring Boot, Tomcat, Jakarta Servlet APIs, or unrelated starter dependencies can prevent startup. This is especially common after manual version overrides.

Use your build tool to inspect the resolved dependency tree:

bash
mvn dependency:tree

Bean Initialization Failure

Sometimes Tomcat is fine, but the web application context fails first because a required bean throws during creation. That still bubbles up as an embedded-container startup failure.

Invalid Web Configuration

Examples include:

  • broken Filter or Servlet registration
  • invalid context path settings
  • malformed configuration properties
  • application code touching unavailable infrastructure during startup

A Small Example of a Startup Failure

This bean throws before the application is ready, which can prevent the server from starting:

java
1import org.springframework.context.annotation.Bean;
2import org.springframework.context.annotation.Configuration;
3
4@Configuration
5class BadConfig {
6    @Bean
7    String requiredValue() {
8        throw new IllegalStateException("Configuration missing");
9    }
10}

In a real project, the Tomcat failure message would often appear above the real exception, but the real fix is to remove the bean failure.

A Better Debugging Routine

Work in this order:

  1. read the first nested exception with a concrete class name
  2. check whether the port is already bound
  3. inspect recent dependency changes
  4. look for beans that perform risky work during startup
  5. confirm Java and Spring Boot version compatibility

That process is faster than changing random properties and rerunning.

Example of Safer Startup Design

Keep startup beans light and defer expensive or fragile work until after the application context is ready:

java
1import org.springframework.boot.CommandLineRunner;
2import org.springframework.context.annotation.Bean;
3import org.springframework.context.annotation.Configuration;
4
5@Configuration
6class AppConfig {
7    @Bean
8    CommandLineRunner runner() {
9        return args -> System.out.println("Application started");
10    }
11}

This is not a cure-all, but it helps separate container startup from later application logic.

Common Pitfalls

  • Treating the Tomcat headline message as the root cause.
  • Changing server.port before checking whether the actual problem is a bean failure.
  • Overriding Spring-managed dependency versions manually without checking compatibility.
  • Doing database or network calls inside bean construction with poor error handling.
  • Reading only the first line of the error output and missing the nested exception that matters.

Summary

  • "Unable to start embedded Tomcat" is usually a wrapper around a more specific startup failure.
  • The real fix comes from the nested exception, not the top-level message.
  • Port conflicts, bean creation errors, and dependency mismatches are the most common causes.
  • Use a structured debugging order instead of changing random settings.
  • Tomcat often fails because the application context failed first.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.