Reputation: 21
I am learning spring cloud and write some codes in Intellij IDEA about spring cloud eureka. Let me describe the problem now.
I have completed successfully a service registry centre(single node).
Now I am changing it to HA mode.
application-peer1.properties:
spring.application.name=eureka-server
server.port=1111
eureka.instance.hostname=peer1
eureka.client.serviceUrl.defaultZone=http://peer2:1112/eureka/
spring.profiles.active=peer1
application-peer2.properties:
spring.application.name=eureka-server
server.port=1112
eureka.instance.hostname=peer2
eureka.client.serviceUrl.defaultZone=http://peer1:1111/eureka/
spring.profiles.active=peer2
application.properties is empty.
In my laptop's Windows 10 C:\Windows\System32\drivers\etc\hosts, add the below lines:
127.0.0.1 peer1
127.0.0.1 peer2
In IDEA terminal, run "mvn install" and generated the .jar file.
Run "java -jar target\eureka-server-0.0.1-SNAPSHOT.jar --spring.profiles.active=peer1". It reports:
org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles.active' imported from location 'class path resource [application-peer1.properties] ' is invalid in a profile specific resource [origin: class path resource [application-peer1.properties] from eureka-server-0.0.1-SNAPSHOT.jar - 12:24]
The pom.xml shows:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
Thanks & regards,
Jie
Upvotes: 0
Views: 1186
Reputation: 53482
The problem is not in your command line argument, the problem is this at property file:
application-peer1.properties:
spring.profiles.active=peer1
you already have "peer1" profile selected from command line argument, so it does not make sense to reactivate the same profile, since it is already active at that point.
If this same line had been in non-profile specific property file such as "application.properties", it could have been used, but not here.
Upvotes: 2