How to configure port for Spring Boot application

This article was translated from: How to configure port for a Spring Boot application

How to configure the TCP / IP port that the Spring Boot application listens to, so it does not use the default port 8080.


#1st Floor

Reference: https://stackoom.com/question/1QSh8/ How to configure the port for the Spring-Boot application


#2nd Floor

As said in docs either set server.portas system property using command line option to jvm -Dserver.port=8090or add application.propertiesin /src/main/resources/with As stated in the documentation, you can use jvm command line options to set to system properties, or add-Dserver.port=8090server.port/src/main/resources/application.properties

server.port=8090

For random port use for random port use

server.port=0

#3rd floor

You can specify port by overriding EmbeddedServletContainerFactorybean within your configuration (java based or xml). You can specify the port by overriding the bean in the configuration (based on Java or XML) EmbeddedServletContainerFactory. There you can specify port for used embedded servlet container. You can specify the port for the embedded servlet container used here. Please, see Spring Boot-Core "Embedded Servlet Container Support" paragraph and example there. Please refer to the Spring Boot- Core "Embedded Servlet Container Support" paragraph and example there . Hope this helps. Hope this helps .


#4th floor

In case you are using application.ymladd the Following lines to it If you are using , please add the following lines in itapplication.yml

server:
     port: 9000

and of course 0 for random port. Of course, it is 0 for random port.


#5th Floor

There are two main ways to change the port in the Embedded Tomcat in a Spring Boot Application. In the Spring Boot application, there are two main ways to change the port in the embedded Tomcat.

Modify application.properties

First you can try the application.properties file in the / resources folder: First, you can try the application.properties file in the / resources folder :

server.port = 8090

application.properties file

Modify a VM option to modify the virtual machine options

The second way, if you want to avoid modifying any files and checking in something that you only need on your local, you can use a vm arg: The second method, if you want to avoid modifying any files and check in only on local To perform the operation, you can use vm arg:

Go to Run- > Edit Configurations-> VM options Go to Run-> Edit Configurations-> VM options

-Dserver.port=8090

Use vm arg to change the port

Additionally, if you need more information you can view the following blog post here: Changing the port on a Spring Boot Application In addition , if you need more information, you can view the following blog post here : Change on the Spring Boot application port


#6th floor

  1. As everyone said, you can specify in application.properties we have said, you can specify application.properties in
    server.port = 9000 (OTHER could BE the any value) server.port = 9000 (can be any other value)

  2. If you are using spring actuator in your project, by default it points to by default it points to 8080 by default
    , and if you want to change it, then in application.properties mention 8080, if To change it, mention
    management.port = 9001 (could be any other value) management.port = 9001 (may be any other value) in application.properties

Published 0 original articles · praised 75 · 560,000 views +

Guess you like

Origin blog.csdn.net/w36680130/article/details/105466179