Yes, Spring Boot allows us to change the default port of the embedded Tomcat server. By default, Spring Boot applications run on port 8080, but this can be easily customized through configuration files, command-line arguments, environment variables, or programmatically.
Method 1: Using application.properties
The most common approach is to configure the port in the application.properties file.
server.port=9090http://localhost:9090
http://localhost:8080
Method 2: Using application.yml
port: 9090
Spring Boot automatically reads the configuration during startup.
Method 3: Using Command-Line Arguments
The port can be overridden while starting the application.
java -jar app.jar --server.port=9090This is useful when deploying the same application to different environments.
Method 4: Using Environment Variables
SERVER_PORT=9090server.port
This approach is commonly used in Docker and cloud deployments.
Method 5: Programmatically
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.Collections;
@SpringBootApplication
public class EmployeeApplication {
public static void main(String[] args) {
SpringApplication app =
new SpringApplication(
EmployeeApplication.class);
app.setDefaultProperties(
Collections.singletonMap(
"server.port",
"9090"));
app.run(args);
}
}This sets the port during application startup.
How It Works Internally
Application Starts
|
Read Configuration
|
Resolve server.port
|
Configure Embedded Tomcat
|
Tomcat Starts on Specified Port
Spring Boot reads the port configuration before initializing the embedded server.
Using Random Port
For testing purposes, Spring Boot can use a random available port.
server.port=0Spring Boot automatically selects an available port at runtime.
Suppose an organization hosts multiple applications on the same server.
server.port=8080
server.port=9090
server.port=7070
Each application can run simultaneously without port conflicts.
Common Use Cases
Benefits
Real-World Example
server.port=8081
server.port=8082
server.port=8080
Spring Boot loads the appropriate configuration based on the active environment, allowing the same application to run on different ports without changing the source code.
A concise interview answer is
Yes, the embedded Tomcat port can be changed in Spring Boot using the server.port property. This can be configured in application.properties, application.yml, environment variables, command-line arguments, or programmatically. The default port is 8080, but it can be changed to any available port as required.
Last updated: 11 November 2026
Previous question: What is Spring Boot dependency management?
Next question: What happens if a starter dependency includes conflicting versions of libraries with other dependencies in the project?