What is the default port of Tomcat in Spring Boot?

The default HTTP port used by the embedded Apache Tomcat server in a Spring Boot application is 8080. When a Spring Boot application starts without any custom server configuration, it automatically listens for incoming requests on port 8080.

Key Points: • Spring Boot uses embedded Tomcat as the default web server. • The default server port is 8080. • The port can be changed through application.properties or application.yml. • If port 8080 is already in use, the application will fail to start. • Other embedded servers like Jetty and Undertow also use port 8080 by default unless configured differently.

How Does It Work?

Application Starts | Embedded Tomcat Starts | Binds to Port 8080 | Accepts HTTP Requests

When the application launches, Tomcat automatically starts and listens on:

http://localhost:8080

Changing the Default Port

Code Example:

application.properties

server.port=9090

After this configuration, the application becomes accessible at:

http://localhost:9090

Using YAML Configuration

Code Example:

server: port: 9090

Random Port Configuration

For testing purposes, Spring Boot can start on a random available port.

Code Example:

server.port=0

Spring Boot automatically selects an unused port.

Example: Suppose you create a Spring Boot REST API:

http://localhost:8080/employees

When the application starts, Tomcat listens on port 8080 and handles all incoming requests to the API endpoints.

Common Default Ports

• Tomcat: 8080 • HTTP Standard Port: 80 • HTTPS Standard Port: 443

Spring Boot uses 8080 because ports 80 and 443 typically require elevated privileges and are often reserved for production environments.

Interview Tip: A concise interview answer is:

"The default port of the embedded Tomcat server in Spring Boot is 8080. If no custom configuration is provided, the application listens for HTTP requests on port 8080. The port can be changed using the server.port property in application.properties or application.yml."