title: Command Line arguments in Spring boot outside main problem
body: <p>I am trying to get command line arguments outside the main method in spring boot application, i tried many methods but none of them is working. I am using spring boot 2.4.5. Following is my code:</p>
  <pre><code>package com.example;
  
  import org.springframework.boot.ApplicationArguments;
  import org.springframework.boot.ApplicationRunner;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class MainClass implements ApplicationRunner {
      public static void main(String[] args){
          SpringApplication.run(MainClass.class);
          for (String arg : args) System.out.println(&quot;MAIN::::&quot;+arg);
      }
  
      @Override
      public void run(ApplicationArguments args) throws Exception {
          System.out.println(&quot;# NonOptionArgs: &quot; + args.getNonOptionArgs().size());
  
          System.out.println(&quot;NonOptionArgs:&quot;);
          args.getNonOptionArgs().forEach(System.out::println);
  
          System.out.println(&quot;# OptionArgs: &quot; + args.getOptionNames().size());
          System.out.println(&quot;OptionArgs:&quot;);
  
          args.getOptionNames().forEach(optionName -&gt; {
              System.out.println(optionName + &quot;=&quot; + args.getOptionValues(optionName));
          });
      }
  }
  </code></pre>
  <p>Here is the output for passing argument: <code>iamnonoption --app.name=CmdRulez --app.hosts=abc,def,ghi --app.name=2</code>:</p>
  <pre><code># NonOptionArgs: 0
  NonOptionArgs:
  # OptionArgs: 0
  OptionArgs:
  MAIN::::iamnonoption
  MAIN::::--app.name=CmdRulez
  MAIN::::--app.hosts=abc,def,ghi
  MAIN::::--app.name=2
  </code></pre>
  <p>Why ApplicationArguments is not getting any arguments?</p>