superwizard
superwizard

Reputation: 21

Error raised when run "java -jar <jar name> --spring.profiles.active=...."

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.

  1. Under the folder \src\main\resources (same folder as application.properties), I created application-peer1.properties and application-peer2.properties, and clean content of application.properties.

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.

  1. 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

  2. In IDEA terminal, run "mvn install" and generated the .jar file.

  3. 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

Answers (1)

eis
eis

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

Related Questions