Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between server.port and local.server.port in Spring Boot?

Why are there two names for the port ?

server.port=.. 

and

 local.server.port

What is the difference between them?

like image 346
Ekaterina Avatar asked Nov 20 '18 14:11

Ekaterina


People also ask

What is local server port?

Localhost is the default name used to establish a connection with a computer. The IP address is usually 127.0. 0.1. This is done by using a loopback address network. Port 80 is the common standard port for HTTP.

What is server port in spring?

The Spring Boot framework provides the default embedded server (Tomcat) to run the Spring Boot application. It runs on port 8080.

How do I specify a server port in spring boot?

The fastest and easiest way to customize Spring Boot is by overriding the values of the default properties. For the server port, the property we want to change is server. port. By default, the embedded server starts on port 8080.

How do I get local server host and port in spring boot?

To get the server address you can use the InetAddress class to get the local ip-address, for the port you can use ${server. port:8080} is you are using tomcat (this trick would also work for the server.


1 Answers

server.port is a way to define a value for the tomcat port of your service. It is used in "application.properties" file. If you do not fix this property, the port 8080 is chosen by default.

local.server.port is used to recover the value of the running port. It is used in the code like that:

@Value("${local.server.port}")
int runningPort;

or like that too:

@LocalServerPort
int runningPort;
like image 85
veben Avatar answered Oct 06 '22 01:10

veben