Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command-Line Arguments broken in 2.2.4? or Am I using it in wrong way? #20115

Closed
vmisra2018 opened this issue Feb 11, 2020 · 6 comments
Closed
Labels
status: duplicate A duplicate of another issue

Comments

@vmisra2018
Copy link

vmisra2018 commented Feb 11, 2020

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]
@vmisra2018 vmisra2018 changed the title Command-Line Arguments broken in 2.2.4? or there is some other way? Command-Line Arguments broken in 2.2.4? or Am I using it in wrong way? Feb 11, 2020
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 11, 2020
@mbhave
Copy link
Contributor

mbhave commented Feb 11, 2020

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

@mbhave mbhave closed this as completed Feb 11, 2020
@mbhave mbhave added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 11, 2020
@vmisra2018
Copy link
Author

vmisra2018 commented Feb 11, 2020

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]

@mbhave
Copy link
Contributor

mbhave commented Feb 11, 2020

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.

@vmisra2018

This comment has been minimized.

@snicoll

This comment has been minimized.

@vmisra2018

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants