title: Best way to load some JSON files into a Spring Boot application
body: <p>I'm about to create a Rest webservice application, and I need to load all JSON files that exist in a folder passed as parameter (in application.yml a priori), on application startup, to use them later in the methods of webservices as a list of beans (every JSON file corresponds to a bean). </p>
  
  <p>A sample to further explain my requirements:</p>
  
  <p><strong>application.yml</strong>:</p>
  
  <pre><code>json.config.folder: /opt/my_application/json_configs
  </code></pre>
  
  <p><strong>MyApplication.java</strong>:</p>
  
  <pre><code>package com.company;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class MyApplication {
      public static void main(String[] args) {
          SpringApplication.run(MyApplication.class, args);
      }
  }
  </code></pre>
  
  <p>JSON Files having this structure:</p>
  
  <pre><code>    {  
     "key":"YYYYY",
     "operator_list":[  
          {  
             "name":"operator1",
             "configs":{  
                 "id":"XXXXX1",
                 "path":"xxxx2"
             }
          },
          {  
              "name":"operator2",
              "configs":{  
                  "id":"XXXXX1",
                  "passphrase":"xxxx2",
                  "user_id":"XXXX3",
                  "password":"XXXXX"
              }
          },
          {  
              "name":"operator3",
              "configs":{  
                  "user_id":"XXXXX1"
              }
          }
      ]
      }
  </code></pre>
  
  <p><strong>RestAPI.java</strong></p>
  
  <pre><code>@RestController
  @RequestMapping("/my_app_url")
  @PropertySource(value={"classpath:application.yml"})
  public class RestAPI {
      //Some fields
      ....
  
      //Some methods
      ....
  
      //Method that return operator list of a given context (correspond to the field "key" of the json file)
      @RequestMapping("/getOperatorList")
      public List&lt;Operator&gt; getOperatorList(@RequestParam(value = "context", defaultValue = "YYYYY") String context) throws Exception{
          List&lt;Operator&gt; result = null;
          //Here, i need to loop the objects , that are supposed to be initialized during application startup 
          //(but i I do not know yet how to do it) with data from JSON files
          //to find the one that correspond to the context in parameter and return its operator list
  
          return result;
      }
  }
  </code></pre>
  
  <p><strong>ContextOperatorBean.java</strong> that will contain JSON file infos a priori:</p>
  
  <pre><code>package com.company.models;
  
  import java.util.List;
  
  public class ContextOperatorBean {
      String key;
      List&lt;Operator&gt; operator_list;
  
      public ContextOperatorBean() {
      }
  
      public ContextOperatorBean(String key, List&lt;PaymentMethod&gt; operator_list) {
          this.key = key;
          this.operator_list = operator_list;
      }
  
      public String getKey() {
          return key;
      }
  
      public void setKey(String key) {
          this.key = key;
      }
  
      public List&lt;Operator&gt; getOperator_list() {
          return operator_list;
      }
  
      public void setOperator_list(List&lt;Operator&gt; operator_list) {
          this.operator_list = operator_list;
      }
  }
  </code></pre>
  
  <p>And another class called Operator.java containing all operator infos.</p>
  
  <p>Is there a method to initialize a <code>ContextOperatorBean</code> object list that contain infos of all JSON files, on application startup, and use them in my webservice methods (RestAPI.java class)?</p>