Understanding Tomcat: From Classic Servlets to Spring Boot Integration
This article explains what Tomcat is, its core functions, how to set up a simple servlet manually, and why Spring Boot hides Tomcat by default while still allowing you to switch to alternatives like Jetty or Undertow.
A few days ago a junior developer received an open‑source project that uses plain Spring (not Spring Boot) and asked how to start it. He had never installed or configured Tomcat, so I pointed him to set up Tomcat manually.
Since Spring Boot embeds Tomcat as the default servlet container, most new Java developers never see Tomcat directly. Spring Boot pulls in spring-boot-starter-web, which brings Tomcat in automatically.
Tomcat
Apache Tomcat is an open‑source Java Servlet container and web server that implements the Servlet, JSP, EL, and WebSocket specifications. The latest Tomcat 11 beta is already released.
Core functions of Tomcat include:
Servlet container : provides the runtime environment for Servlets and manages their lifecycle.
Web server : handles HTTP requests and serves static resources.
JSP engine : compiles JSP pages into Servlets and executes them.
If you use plain Servlets without Spring, creating a runnable project is straightforward. Example servlet:
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().println("Hello, Tomcat!");
}
}Corresponding web.xml configuration:
<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>When Spring arrived, most Java web projects switched to it, and later Spring Boot further simplified development by auto‑configuring Tomcat, so developers no longer need to worry about JAR vs WAR packaging or manual Tomcat setup.
Spring Boot also allows you to replace the embedded Tomcat with other servers such as Jetty or Undertow. To use Jetty, first exclude the default Tomcat dependency:
<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>Then add the Jetty starter:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>In summary, while many developers never interact directly with Tomcat because Spring Boot hides it, understanding Tomcat’s role and how to configure alternatives remains valuable for deeper Java backend knowledge.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
