title: Spring boot - load initial data from a json file
body: <p>I have spring boot project, which uses hibernate spatial. I also have a json file, that contains data, which I would like to import to a database (postgresql).</p>
  
  <p>I would prefer if I could execute this as a separate java "script" application from the commandline or from IntelliJ IDEA. But, it would still use the hibernate classes of the main application (entities for example). What I would want to do is:</p>
  
  <ol>
  <li>Launch the java program from commandline with a parameter that tells the location of the json file, which contains the data</li>
  <li>Parse the json file somehow, and loop through its main array.</li>
  <li>On each loop, I would want to get some values from the current json array object, and then instantiate a hibernate entity object, and save it to the database.</li>
  </ol>
  
  <p>What do you think would be the best way to achieve this?</p>
  
  <p>I found <a href="https://spring.io/guides/gs/batch-processing/" rel="nofollow noreferrer">spring-boot-starter-batch</a> module, but it feels like it has so much overhead and complexity for a such an easy and simple task to do. What I'm also wondering why is there zero examples of loading data from a json file? One could think that is very common task.</p>
  
  <p>I also found <a href="http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/ApplicationRunner.html" rel="nofollow noreferrer">ApplicationRunner</a> (<a href="https://stackoverflow.com/questions/38040572/spring-boot-loading-initial-data">one example also here</a>), which could fit for the job. It is run on application startup. I wouldn't want to run it always on startup, but at least I could run it now, and then disable that code. But I don't know how to use it fully really. Any help is much appreciated!</p>