Backend Development 6 min read

Understanding Tomcat and Its Integration with Spring Boot

Apache Tomcat is the underlying servlet container and web server that Spring Boot automatically embeds via the spring‑boot‑starter‑web dependency, but junior developers often miss its core roles—managing servlet lifecycles, serving static resources, and compiling JSPs—so learning Tomcat (or swapping it for Jetty by adjusting Maven exclusions) clarifies what Spring Boot abstracts and enables flexible container choices.

Java Tech Enthusiast
Java Tech Enthusiast
Java Tech Enthusiast
Understanding Tomcat and Its Integration with Spring Boot

Many junior Java developers start directly with Spring Boot and never encounter the underlying servlet container, typically Apache Tomcat.

Apache Tomcat is an open‑source Java Servlet container and web server that implements the Servlet, JSP, EL and WebSocket specifications. Its core functions are:

Servlet container – manages servlet lifecycle.

Web server – serves static HTTP resources.

JSP engine – compiles JSP to servlets.

A minimal pure‑Spring (non‑Boot) web application can be built by writing a servlet and configuring web.xml :

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.getWriter().println("Hello, Tomcat!");
    }
}
<web-app>
    <servlet>
        <servlet-name>HelloServlet</servlet-name>
        <servlet-class>com.example.HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloServlet</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>
</web-app>

Spring Boot simplifies this by embedding Tomcat automatically through the spring-boot-starter-web dependency, so developers usually do not need to manage the container themselves.

If you prefer another embedded server such as Jetty, you can exclude the default Tomcat starter and add the Jetty starter in your pom.xml :

<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>

Understanding Tomcat’s role helps developers appreciate what Spring Boot abstracts away and gives them the flexibility to switch containers when needed.

JavaSpring BootWeb DevelopmentServletTomcat
Java Tech Enthusiast
Written by

Java Tech Enthusiast

Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.