Configuring Port for a Spring Boot Application
When deploying a Spring Boot application, it's often necessary to specify a specific port for it to listen on, rather than relying on the default port (8080). This can be achieved through a few simple configuration methods.
Configure using System Property
One option is to use a system property when starting the application, using the -Dserver.port argument. For example:
java -Dserver.port=8090 -jar my-app.jar
Configure using Application Properties or YAML
Alternatively, you can create an application.properties or application.yml file and set the server.port property within it. Place the file in the /src/main/resources/ directory.
application.properties:
server.port=8090
application.yml:
server: port: 8090
Use a Random Port
If you want the application to listen on a random port, assign the value 0 to server.port:
server.port=0
server: port: 0
The above is the detailed content of How Can I Configure the Port for My Spring Boot Application?. For more information, please follow other related articles on the PHP Chinese website!