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
Mary-Kate OlsenOriginal
2024-12-05 00:05:111038browse

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

Application Properties/YAML Configuration

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

server.port=8090

For a random port, set the value to 0:

server.port=0

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

server:
  port: 8090

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!

Statement:
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