Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading