title: how to run two different spring boot instances?
body: <p>I have a need to run two separate spring boot instances, the first instance is responsible for some code-generation, while the second is serves as an API.</p>
  
  <p>Here is the process:
  1. Run the generation spring boot app
  2. After the generation is shutdown, run the API spring boot app</p>
  
  <pre class="lang-java prettyprint-override"><code>// Api.java
  
  @Log4j2
  @EnableEurekaClient
  @SpringBootApplication
  public class Api {
      public static void main(String[] args) {
          SpringApplication.run(Api.class, args);
      }
  }
  
  // Generator.java
  @Log4j2
  @EnableEurekaClient
  @SpringBootApplication
  public class Generator implements CommandLineRunner {
  
      public static void main(String[] args) {
          SpringApplication.run(Generator.class, args);
          Api.run(args); // run the API instance
      }
  
      @Override
      public void run(String... args) throws Exception {
          // do generation here
      }
  }
  </code></pre>
  
  <p>Exact error:
  <code>Error creating bean with name 'nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication</code></p>
  
  <p>The error I'm currently getting is that there is already a spring boot instance, and hence can not call <code>Api.run(args)</code>.  I'd like to be able to run both of these one after another.  If there is a better way I'm all ears.  At the end of the day it needs to be a single runnable jar.  My main class is configured to point to the Generation, and theoretically it should generate the code then run the Api. </p>