Home > Java > javaTutorial > How Can I Change the Default Port of My Spring Boot Application?

How Can I Change the Default Port of My Spring Boot Application?

Mary-Kate Olsen
Release: 2024-12-05 00:05:11
Original
859 people have browsed it

How Can I Change the Default Port of My Spring Boot Application?

Customizing Spring Boot Application Port

Spring Boot applications typically listen on port 8080 by default. However, you may need to configure a different port for various reasons. Here are the steps to do so:

System Property Configuration

You can configure the server port using the -Dserver.port=PORT_NUMBER system property:

java -jar my-app.jar -Dserver.port=8090
Copy after login

Application Properties/YAML Configuration

Alternatively, you can create an application.properties file in /src/main/resources/ and add the following:

server.port=8090
Copy after login

For a random port, set the value to 0:

server.port=0
Copy after login

For YAML configuration, create an application.yml file in /src/main/resources/ and include:

server:
  port: 8090
Copy after login

By using these methods, you can configure the port listened on by your Spring Boot application to the desired value.

The above is the detailed content of How Can I Change the Default Port of 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