简体   繁体   中英

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.

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.

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);
}

I know its an old post, but I might know the answer(maybe it will help others): There is a hierarchy with the configuration settings.

The applicaton.properties file is at the bottom (OS env. variables, Java System properties etc. are all above), on the other hand, terminal parameters are at the top .

So when the server initialized, it used the port from a property setting, that is higher in the hierarchy ladder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM