server.port properties not working after buildin spring boot project
Solution 1
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:
- A /config subdirectory of the current directory.
- The current directory
- A classpath /config package
- 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.
Solution 2
I encountered the same problem, in my case, I didn't pass the args to SpringApplication.
public static void main(String[] args) {
SpringApplication.run(MySpringConfiguration.class);
}
should be
public static void main(String[] args) {
SpringApplication.run(MySpringConfiguration.class, args);
}
James
Updated on July 15, 2022Comments
-
James almost 2 years
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 commandjava -jar jarfilename.jar
but it says the port8080
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 number8090
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.