title: Spring boot - How to create spring beans for the objects created in static methods
body: <p>I am trying to move old project to spring boot project. I created the spring project project and moved the code and now I am trying to springify the project by creating beans for the objects.</p>
  <pre><code>@SpringBootApplication
  public class TestApplication implements CommandLineRunner {
  
      public static void main(String[] args) {
          SpringApplication.run(TestApplication.class, args);
      }
  
      @Override
      public void run(String... args) throws CmdLineException {
  
          final CommandLineArgs arguments = new CommandLineArgs();
          CmdLineParser parser = new CmdLineParser(arguments);
          parser.parseArgument(args);
          A.generatedData(arguments);
      }
  }
  
  class A{
      public static void generatedData(CommandLineArgs arguments) {
          LOG.info(&quot;Starting visualization.&quot;);
  
          B b = new B(createModel(arguments));
          b.build();
      }
      
      private static Model createModel(CommandLineArgs arguments) {
          ...
      }
  }
  
  class B{
      public void build() {
          ...
      }
  }
  </code></pre>
  <p>Some objects are created within the static method so I am not sure how to create beans of those objects. Can you please help convert this code in the spring world?</p>