Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

server.port properties not working after buildin spring boot project

i'm working on spring boot project and all works fine , now i want to build and run the app. in the application.properties file i set the property server.port = 8090 after building the project using maven i run the following command java -jar jarfilename.jar but it says the port 8080 is already in use. i try these commands:

java -jar  -Dport=8090 jarfilename.jar

and

java -jar  jarfilename.jar --port=8090

but also i got the same message the port 8080 is already in use.

I'm wondering why it takes the port number 8080 and ignore the port number 8090 that i set in the application.properties file.

Note : (I'm using tomcat embedded server) and when i check the folder target/classes.. application.properties i didn't find the property server.port=8090.

can anyone explain to me what' happen exacly? thanks in advance.

like image 844
James Avatar asked Jan 04 '23 19:01

James


1 Answers

Is the application.properties located at the right location? Description from Spring.io:

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:

  1. A /config subdirectory of the current directory.
  2. The current directory
  3. A classpath /config package
  4. The classpath root

The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations).

Use java -jar -Dserver.port=8090 jarfilename.jar to set the port from command line.

Hint, from Spring.io: If you want to use the short term -Dport=8090, you can use server.port=${port:8080} in your application property file.

like image 71
iBiber Avatar answered Jan 14 '23 06:01

iBiber