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.
🌐
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 - Choose a different port: Simply update the port in the configuration or command line as shown above to use an available port. You can identify which process is using a port by running the following command in the terminal: ... Spring Boot makes it incredibly easy to change the default port in multiple ways, whether through configuration files, programmatically, or via command-line arguments.
🌐
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 - P.S Tested with Spring Boot 1, ... port: 8181 · Using the command line, we can change the port using the server.port property as the command line argument....
🌐
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 - Add the following lines to specify the desired port: ... Replace your_desired_port_number with the port number you want to use. Save the file and restart your Spring Boot application to apply the changes.
🌐
Stack Abuse
stackabuse.com › how-to-change-port-for-spring-boot-applications
How to Change Port for Spring Boot Applications
January 19, 2022 - If you're using Maven, when starting up your application, include a JVM argument: $ mvn spring-boot:run -Dspring-boot.run.jvmArguments='-Dserver.port=8090' Or, if you're using Spring's own CLI, you can pass in command-line arguments separate from Spring's command arguments by adding an additional, ...
🌐
Spring
docs.spring.io › spring-boot › docs › 1.3.3.RELEASE › reference › html › howto-properties-and-configuration.html
69. Properties & configuration
A separate Environment property source is set up for this document and it can be overridden by system properties, environment variables or the command line. No matter what you set in the environment, Spring Boot will always load application.properties as described above. If YAML is used then files with the ‘.yml’ extension are also added to the list by default. Spring Boot logs the configuration files that are loaded at DEBUG level and the candidates it has not found at TRACE level. See ConfigFileApplicationListener 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.
🌐
Javatpoint
javatpoint.com › spring-boot-change-port
Spring Boot Change Port
May 30, 2014 - SB Change Port - Spring Boot Change Port with Introduction, Features, Project, Starter Project Wizard, CLI, Application, Annotations, DM, Properties, Actuator, Thymeleaf View, JPA, JDBC etc
Find elsewhere
🌐
Spring
docs.spring.io › spring-boot › docs › 1.3.0.RELEASE › reference › html › howto-properties-and-configuration.html
69. Properties & configuration - Spring
A separate Environment property source is set up for this document and it can be overridden by system properties, environment variables or the command line. No matter what you set in the environment, Spring Boot will always load application.properties as described above. If YAML is used then files with the ‘.yml’ extension are also added to the list by default. Spring Boot logs the configuration files that are loaded at DEBUG level and the candidates it has not found at TRACE level. See ConfigFileApplicationListener 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.
🌐
TutorialsPoint
tutorialspoint.com › spring_boot › spring_boot_application_properties.htm
Spring Boot - Application Properties
spring: application: name: demoservice server: port: 9090 · Instead of keeping the properties file under classpath, we can keep the properties in different location or path. While running the JAR file, we can specify the properties file path. You can use the following command to specify the location of properties file while running the JAR −
🌐
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 - Create an application.properties file under src/main/resources and define the server.port attribute inside it: ... You can customize the properties of the default servlet container by implementing the EmbeddedServletContainerCustomizer interface as follows: package com.programmer.gate; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; public class CustomContainer implements EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { container.setPort(9090); } }
🌐
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 - You can achieve the same result by using the --server.port command line argument: java -jar myapp.jar --server.port=8082 · Finally, you can change the port programmatically by using the WebServerFactoryCustomizer interface. However, I don't recommend this approach since the HTTP server port is part of the application configuration and shouldn't be hardcoded in the source code. import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.stereotype.Component; @Component
🌐
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 - We can change the default embedded server port to any other port number, using any one of the several techniques such as: ... When defined in multiple places, it is also the order of priority. 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.
🌐
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › change-default-port-in-spring-boot
How to Change the Default Port in Spring Boot? - GeeksforGeeks
May 31, 2024 - Also, we can change the default ... the command line. This happens when the application is in a running state or we can say after development. Default port number: 8080 Default Context path: '/' We can change the default port number for embedded server in Spring Boot application ...
🌐
Blogger
javahungry.blogspot.com › 2019 › 09 › change-default-port-of-spring-boot.html
5 Ways : How to Change Default Port of Embedded Server in Spring Boot | Java Hungry
There are two ways : a. We can pass the argument --server.port=desired_port_number while running the application using command java -jar springbootapplication.jar as shown below : java -jar springbootapplication.jar --server.port=8089 Or b. you can change the port by passing the System property ...
🌐
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 - In this guide, we’ll show you three easy ways to change the port of a Spring Boot application, so your service runs exactly where you want it. ... You have multiple services on the same server. Port 8080 is already in use. Your DevOps or security policies require custom ports. 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:
🌐
Apps Developer Blog
appsdeveloperblog.com › home › spring framework › spring boot › start spring boot application on a different port number
Start Spring Boot Application on a Different Port Number - Apps Developer Blog
October 22, 2022 - Below is an example of how you can start up your Spring Boot application and set the server.port number property via a command-line argument.
🌐
Attacomsian
attacomsian.com › blog › spring-boot-change-default-port
How to change the default port in Spring Boot
October 11, 2022 - For example, if you are packaging and running the application as a jar file, you can set the server.port argument with the Java command: $ java -jar spring-boot-app.jar --server.port=8888 ...