Reputation: 1466
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.
Upvotes: 8
Views: 29514
Reputation: 1
Possibly it is the Tomcat management port that is use that prevents you from starting the tomcat web server instance. try : server.management.port = 8090
Upvotes: 0
Reputation: 116
I configured SERVER_PORT environment variable and had same problem. With this variable configured, the application.properties does not work. After remove environment variable "SERVER_PORT" or just edit it, I could change the port.
Reference: Spring - 78.3 Change the HTTP Port
Upvotes: 0
Reputation: 11
The application.properties file is excluded.
Go to project properties -> Java Build Path -> <Choose your project's /src/main/resources> -> Double click on Excluded -> Remove (** pattern mostly) -> Apply.
Now recheck
Upvotes: 1
Reputation: 1
when you create spring boot application using 'spring initializer' select jar file
Upvotes: 0
Reputation: 35
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.
Upvotes: -1
Reputation: 406
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);
}
Upvotes: 6
Reputation: 172
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.
Upvotes: 7