Home > Java > javaTutorial > How Can I Configure the Port for My Spring Boot Application?

How Can I Configure the Port for My Spring Boot Application?

Susan Sarandon
Release: 2024-12-14 03:45:13
Original
636 people have browsed it

How Can I Configure the Port for My Spring Boot Application?

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
Copy after login

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
Copy after login

application.yml:

server:
  port: 8090
Copy after login

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
Copy after login
server:
  port: 0
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template