title: How to reuse classes in a Spring Boot REST application?
body: <p>I have a Spring Boot REST application with JPA entities and Repository classes (and related services) that works very well.  Now I would like to reuse these classes for other purposes, like weekly CRON jobs and similar one-time processes which will be run from the command line. </p>
  
  <p>What would be the best way to do this?  The challenge is that the persistence context properties are set in application.properties, and the persistence context isn't initialized unless the Application class is initialized.</p>
  
  <p>I can break out all of these classes into a separate project, and use a different way to define the persistence context there, but this becomes more of a maintenance headache if anything changes with the entities or DAO methods.</p>
  
  <p>What I would really like is to have a way, from the command line, to tell Spring Boot to run another class instead of the main Application (and have the persistence context properly initialized).  Any way to do this?</p>
  
  <p>(Note I asked a similar question which got no response: <a href="https://stackoverflow.com/questions/41028858/possible-to-use-spring-boot-repositories-from-another-main-class">Possible to use Spring Boot repositories from another main class?</a>)</p>
  
  <p>[Edit] is it possible to do this by creating a @component that implements the CommandLineRunner?  I just want it to run a simple one-time process and not the full REST application.</p>