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

How Can I Configure the Server Port in My Spring Boot Application?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-03 10:31:10532browse

How Can I Configure the Server Port in My Spring Boot Application?

Configuring Port Configuration in Spring Boot Applications

When developing Spring Boot applications, it's often necessary to configure the TCP/IP port on which the application listens. By default, Spring Boot uses port 8080. To change this, you can leverage several configuration options.

Setting Server Port Property

A straightforward method is to set the server.port property as a system property using the -D command line option for the Java virtual machine (JVM):

-Dserver.port=8090

Using application.properties

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

server.port=8090

Using application.yml

In a similar vein, you can use a application.yml file in /src/main/resources/ and specify the port:

server:
  port: 8090

Enabling Random Ports

If you need to bind to a random port, you can use the following value:

server.port=0

By leveraging these configuration options, you can customize the port number your Spring Boot application listens on, ensuring it aligns with your desired network configuration.

The above is the detailed content of How Can I Configure the Server Port in 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