As said in docs either set server.port as system property using command line option to jvm -Dserver.port=8090 or add application.properties in /src/main/resources/ with

server.port=8090

For a random port use:

server.port=0

Similarly add application.yml in /src/main/resources/ with:

server:
  port: 8090
Answer from Paul Verest on LinkedIn on Stack Overflow
🌐
Baeldung
baeldung.com › home › spring › spring boot › how to change the default port in spring boot
How to Change the Default Port in Spring Boot | Baeldung
July 25, 2025 - The fastest and easiest way to customize Spring Boot is by overriding the values of the default properties. For the server port, the property we want to change is server.port. By default, the embedded server starts on port 8080.
🌐
Medium
medium.com › @rihab.beji099 › how-to-change-the-default-port-in-spring-boot-multiple-approaches-e56e79f601b6
How to Change the Default Port in Spring Boot (Multiple Approaches) | by Rihab Beji | Medium
October 24, 2024 - The most straightforward way to change the default port in Spring Boot is to modify the application.properties file located in the src/main/resources directory.
🌐
Spring
docs.spring.io › spring-boot › docs › 1.3.0.RELEASE › reference › html › howto-properties-and-configuration.html
69. Properties & configuration - Spring
Spring Boot logs the configuration ... for more detail. Some people like to use (for example) --port=9000 instead of --server.port=9000 to set configuration properties on the command line....
🌐
GeeksforGeeks
geeksforgeeks.org › java › change-default-port-in-spring-boot
How to Change the Default Port in Spring Boot? - GeeksforGeeks
May 31, 2024 - The change can happen during development. Also, we can change the default port number of the server along with the context path using the command line. This happens when the application is in a running state or we can say after development.
🌐
Blogger
javarevisited.blogspot.com › 2023 › 07 › 6-ways-to-configure-port-for-spring.html
6 Ways to Change Default Port in Spring Boot? Example Tutorial
August 11, 2023 - To change the port, open the application.properties file and add the following line: ... Replace your_desired_port_number with the port number you want to use. Save the file and restart your Spring Boot application.
🌐
Medium
rameshfadatare.medium.com › how-to-change-the-default-port-in-spring-boot-2c70eefb92aa
How to Change the Default Port in Spring Boot | by Ramesh Fadatare | Medium
September 21, 2024 - You can override the default port by passing a command-line argument when running the application. This method is useful for temporary changes or for running the application on different ports in different environments without changing the code ...
🌐
Spring
docs.spring.io › spring-boot › docs › 1.3.3.RELEASE › reference › html › howto-properties-and-configuration.html
69. Properties & configuration
Spring Boot logs the configuration ... for more detail. Some people like to use (for example) --port=9000 instead of --server.port=9000 to set configuration properties on the command line....
Find elsewhere
🌐
Mkyong
mkyong.com › home › spring boot › how to change the default port in spring boot
How to change the default port in Spring Boot - Mkyong.com
August 16, 2023 - We can update the `server.port` property in `application.properties` to change the default port in Spring Boot.
🌐
Stack Abuse
stackabuse.com › how-to-change-port-for-spring-boot-applications
How to Change Port for Spring Boot Applications
January 19, 2022 - In this short tutorial, we've taken a quick look at three ways to change the default port of a Spring Boot application. You can change the default port by modifying the appropriate properties file, programmatically by implementing a WebServerFactoryCustomizer or via the CLI.
🌐
Gopi Gorantala
ggorantala.dev › how-to-configure-port-for-a-spring-boot-application
How To Configure a Port For a Spring Boot Application
May 6, 2025 - Now let’s go over the different methods to configure the port. The simplest way to change the port is by adding the following line to your src/main/resources/application.properties file:
🌐
DZone
dzone.com › coding › frameworks › changing the default port of spring boot apps [snippets]
Changing the Default Port of Spring Boot Apps [Snippets]
March 19, 2018 - In order to change the default port, you just need to modify the server.port attribute, which is automatically read at runtime by Spring Boot applications. In this tutorial, we provide a few common ways of modifying the server.port attribute. Create an application....
🌐
HowToDoInJava
howtodoinjava.com › home › spring boot › spring boot: change default port of embedded server
Spring Boot: Change Default Port of Embedded Server
May 27, 2024 - To scan for a free port (using OS natives to prevent clashes), use ‘server.port=0‘. Now Spring boot will find any unassigned HTTP port for us. The WebServerFactoryCustomizer interface is used to customize the embedded server configuration. Any beans of this type will get a callback with the container factory before the container itself is started, so we can set the port, address, error pages etc.
🌐
Marc Nuri
blog.marcnuri.com › home › spring boot: how to change the application port?
Spring Boot: How to change the application port? - Marc Nuri
November 9, 2023 - In this quickie, I'll show you how to change the default port. The easiest way to change the default port is by setting the server.port property in the application.properties file.
🌐
ADevGuide
adevguide.com › home › blog › an easy step-by-step guide to changing server port in a spring boot application [4 ways]
An Easy Step-By-Step Guide to Changing Server Port in a Spring Boot Application [4 Ways] | ADevGuide
February 10, 2026 - 2. Microservices Architecture Running ... be your primary security measure. The most straightforward method is configuring the port in your application.properties file located in src/main/resources/....
🌐
Namastecode
namastecode.com › posts › configure-the-port-for-a-spring-boot-application
Configuring the Port for a Spring Boot Application · Namastecode
September 9, 2024 - Let’s begin. The easiest way to change the default port is to configure the server.port property in a properties file located in /src/main/resources/. We can find this property in the application.properties if the application uses the standard configuration:
🌐
TutorialsPoint
tutorialspoint.com › spring_boot › spring_boot_application_properties.htm
Spring Boot - Application Properties
No need to use the separate file like application.properties. The following is an example code to keep the Spring active profiles in application.yml file. Note that the delimiter (---) is used to separate each profile in application.yml file. spring: application: name: demoservice server: port: 8080 --- spring: profiles: dev application: name: demoservice server: port: 9090 --- spring: profiles: prod application: name: demoservice server: port: 4431
🌐
DEV Community
dev.to › nilan › how-to-change-spring-boot-default-port-2345
How to Change Spring Boot Default Port? - DEV Community
April 23, 2022 - In the application.properties file, we can set a custom port number for the property server.port ... Note − If the server.port number is 0 while starting the Spring Boot application, Tomcat uses the random port number based on the availability.
🌐
Spring
docs.spring.io › spring-boot › docs › 2.0.5.RELEASE › reference › html › howto-embedded-web-servers.html
75. Embedded Web Servers
If your classpath contains the necessary bits to start a web server, Spring Boot will automatically start it. To disable this behaviour configure the WebApplicationType in your application.properties, as shown in the following example: ... In a standalone application, the main HTTP port defaults to 8080 but can be set with server.port (for example, in application.properties or as a System property).