I have a bootstrap.yml file which has placeholders but it seems when I use springboot 2.2.4 .RELEASE, it does not pick up those placeholders but same code works successfully for 2.2.2 RELEASE Also , the placeholder as number gives throws java.lang.NumberFormatException for 2.2,4.RELASE. Although I have spring clould version Hoxton.SR1 but it looks more of a springboot issue (?) .

When I run as spring boot ,I am passing multiple command line arguments

mvn spring-boot:run -Dspring-boot.run.arguments=--SEQUENCE_NO=1,--spring.profiles.active=zone1

bootstrap.yml

---
spring:
  application:
    name: dummy-service
  profiles: zone1
  cloud:
    config:
      uri: http://localhost:8890
      fail-fast: true
      profile: sit
eureka:
  instance:
    instanceId: ${spring.cloud.client.hostname}:${spring.application.name}:${server.port}
    prefer-ip-address: true
    metadataMap:
      zone: zone1
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
server:
  port: ${PORT:1100${SEQUENCE_NO}}
---
spring:
  application:
    name: dummy-service
  profiles: zone1
  cloud:
    config:
      uri: http://localhost:8890
      fail-fast: true
      profile: sit
eureka:
  instance:
    instanceId: ${spring.cloud.client.hostname}:${spring.application.name}:${server.port}
    prefer-ip-address: true
    metadataMap:
      zone: zone1
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
server:
  port: ${PORT:1100${SEQUENCE_NO}}
---
spring:
  application:
    name: dummy-service
  profiles: zone2
  cloud:
    config:
      uri: http://localhost:8890
      fail-fast: true
      profile: sit
eureka:
  instance:
    instanceId: ${spring.cloud.client.hostname}:${spring.application.name}:${server.port}
    prefer-ip-address: true
    metadataMap:
      zone: zone1
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
server:
  port: ${PORT:1100${SEQUENCE_NO}}







Output when I run with 2.2.4.RELEASE :

Caused by: java.lang.NumberFormatException: For input string: "11001,--spring.profiles.active=zone1"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_232]
        at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_232]
        at java.lang.Integer.valueOf(Integer.java:766) ~[na:1.8.0_232]
        at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:211) ~[spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE]
        at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:62) ~[spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE]

If I hardcode the ports to 11001 and 11002,it always picks up the second entry and starts on port 11002 I tried to print put arguments in my code


@SpringBootApplication
@EnableDiscoveryClient
public class DummyServiceApplication implements ApplicationRunner {
    //public class DummyServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(DummyServiceApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("Command-line arguments: {}" + Arrays.toString(args.getSourceArgs()));
        System.out.println("Non Option Args: {}" + args.getNonOptionArgs());
        System.out.println("Option Names: {}" + args.getOptionNames());

        for (String name : args.getOptionNames()) {
            System.out.println("arg-" + name + "=" + args.getOptionValues(name));
        }
    }

}

And I see this in logs

Command-line arguments: {}[--SEQUENCE_NO=1,--spring.profiles.active=zone1]
Non Option Args: {}[]
Option Names: {}[SEQUENCE_NO]
arg-SEQUENCE_NO=[1,--spring.profiles.active=zone1]

But with 2.2.2.RELEASE , it works and properly identities and starts on proper ports

Command-line arguments: {}[--SEQUENCE_NO=1, --spring.profiles.active=zone1]
Non Option Args: {}[]
Option Names: {}[SEQUENCE_NO, spring.profiles.active]
arg-SEQUENCE_NO=[1]
arg-spring.profiles.active=[zone1]

Comment From: mbhave

This looks like a duplicate of #19998. Please see this comment on how to pass multiple arguments on the command-line.

Comment From: vmisra2018

Hi Madhura, I am not clear with the explanation given there. Could you please paste me correct command for my params ?

I tried

mvn spring-boot:run -Dspring-boot.run.arguments=SEQUENCE_NO=1 spring.profiles.active=zone1
[ERROR] Unknown lifecycle phase "spring.profiles.active=zone1". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

Comment From: mbhave

This should work for you

mvn spring-boot:run -Dspring-boot.run.arguments="--SEQUENCE_NO=1 --spring.profiles.active=zone1"

If you have any other questions, please join us on Gitter.

Comment From: vmisra2018

Thanks Madhura. This worked with mvn. How do i run this with java as springboot jar? Tried

java -jar target/dummy-service-0.0.1-SNAPSHOT-exec.jar -Dspring-boot.run.arguments="--SEQUENCE_NO=1 --spring.profiles.active=zone1"

and

java -jar target/dummy-service-0.0.1-SNAPSHOT-exec.jar -Dspring-boot.run.arguments="--SEQUENCE_NO=1 --spring.profiles.active=zone1"

and

java -jar target/dummy-service-0.0.1-SNAPSHOT-exec.jar -D"SEQUENCE_NO=1 spring.profiles.active=zone1"

Comment From: snicoll

@vmisra2018 Madhura already mentioned to ask further questions on Gitter.

Comment From: vmisra2018

Ok. Would ask.