There are two ways to change the port of a Spring Boot application:
- Using the
server.port
property: This is the most common way to change the port of a Spring Boot application. You can set theserver.port
property in theapplication.properties
orapplication.yml
file. For example, to set the port to 9000, you would add the following line to your configuration file:
server.port=9000
- Using the
--server.port
command-line argument: You can also change the port of a Spring Boot application using the--server.port
command-line argument. For example, to start the application on port 9000, you would use the following command:
java -jar my-application.jar --server.port=9000
Which method you use to change the port of your Spring Boot application depends on your preference. If you are deploying your application to a production environment, it is generally recommended to set the server.port
property in your configuration file. This will make it easier to manage the port of your application.
Note: If you are using Spring Boot Actuator, you will also need to change the port of the actuator endpoints. You can do this by setting the management.port
property in your configuration file.
Here is an example of a Spring Boot configuration file that sets the port to 9000 and the actuator port to 9001:
server.port=9000
management.port=9001
Once you have changed the port of your Spring Boot application, you can start the application as usual.
No comments:
Post a Comment