I have the following services:
I use "Config First" mode. It means I start Config Server first and after that I start Discovery Service.
Then I run event service. It takes configuration from Config Server. In configuration I specify server.port property equals to 8081.
I see that my event service is being registered in discovery service.
The issue comes when I'm trying to start one more instance of event service. To run it on a different port, I use -Dserver.port vm argument. So my command looks like:
java -jar event-service.jar -Dserver.port=8082
But application fails to start, saying that 8081 is already in use. It seems like event service uses configuration from config server and this configuration takes precedence over VM arguments. But I was thinking that it should be vice-verca.
The order of your command line arguments is wrong: the system variable
must be before the jarfile:
$ java -jar -Dserver.port=8082 event-service.jar
$ server_port=8082 java -jar event-service.jar
$ java -jar -Dserver.port=8082 event-service.jar
$ java -jar event-service.jar --server.port=8082
Notice that for environment variable
, the dots
are replaced with underscores
.
source: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html