title: Spring Boot Application with Two Entrypoints: CLI and Web Service
body: <p>I have a spring-boot-starter application that I created that started as a CommandLineRunner that runs in Kubernetes as a CronJob, something like:</p>
  
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  @EnableAutoConfiguration
  public class JobApplication implements CommandLineRunner {
    Logger logger = LoggerFactory.getLogger(JobApplication.class);
  
  
    public static void main(String[] args) {
      ConfigurableApplicationContext context = SpringApplication.run(JobApplication.class, args);
      context.close();
    }
  
    @Override
    public void run(String... args) throws Exception {
      // run the job
    }
  }
  </code></pre>
  
  <p>I currently run the application in a Dockerfile like this and everything works fine.</p>
  
  <pre><code>CMD java -jar /job/job.jar
  </code></pre>
  
  <p>In this Application there's some Database code and DTOs that I'd like to use and expose as a Spring Web Service, ideally inside the same codebase so I don't have to create multiple Github repos and Java projects and publish a shared library that both use. I'd like to keep it simple and just be able to compile and use them directly.</p>
  
  <p>Is there a way to do that? I think I'd need a second WebApplication class, but then I'm not sure how to execute it so it uses that instead of the Job.</p>
  
  <p>If not, is there a recommended approach to do what I want to do (building multiple jars is ok if that's the only way... but I'd really like to keep all the code in the same project)?</p>