title: How to read properties from application.yml file in spring-boot application
body: <p>My application has nested properties stored in applicaion.yml file.<br/>
  I want to map those properties to <strong>POJO</strong> at the application boot-up.<br/>
  <br/>
  <strong>Application.yml</strong>:<br/></p>
  
  <pre><code>    demo:
       - A:
         - type: A
           prop1: 1
           prop2: 2
           proop3: 3
         - type: B
           prop1: 1
           prop2: 2
           proop3: 3
       - B:
         - type: A
           prop1: 1
           prop2: 2
           proop3: 3
         - type: B
           prop1: 1
           prop2: 2
           proop3: 3
  </code></pre>
  
  <p>In order to achieve that, I am using below annotations:<br/><br/>
  @Configuration<br/>
  @EnableConfigurationProperties<br/>
  @ConfigurationProperties("demo")<br/></p>
  
  <p>Class Demo: <br/><br/></p>
  
  <pre><code>@Configuration
  @EnableConfigurationProperties
  @ConfigurationProperties("demo")
  public class Demo {
      @JsonProperty("A")
      private List&lt;A&gt; a = null;
      @JsonProperty("B")
      private List&lt;B&gt; b = null;
  
      @JsonProperty("A")
      public List&lt;A&gt; getA() {
          return a;
      }
  
      @JsonProperty("A")
      public void setA(List&lt;A&gt; a) {
          this.a = a;
      }
  
      @JsonProperty("B")
      public List&lt;B&gt; getB() {
          return b;
      }
  
      @JsonProperty("B")
      public void setB(List&lt;B&gt; b) {
          this.b = b;
      }
  
      @Override
      public String toString() {
          return "Demo [a=" + a + ", b=" + b + "]";
      }   
  }
  </code></pre>
  
  <p><br/><br/>
  Class A:
  <br/></p>
  
  <pre><code>public class A {
  
      @JsonProperty("type")
      private String type;
      @JsonProperty("prop1")
      private Integer prop1;
      @JsonProperty("prop2")
      private Integer prop2;
      @JsonProperty("proop3")
      private Integer proop3;
  
      @JsonProperty("type")
      public String getType() {
          return type;
      }
  
      @JsonProperty("type")
      public void setType(String type) {
          this.type = type;
      }
  
      @JsonProperty("prop1")
      public Integer getProp1() {
          return prop1;
      }
  
      @JsonProperty("prop1")
      public void setProp1(Integer prop1) {
          this.prop1 = prop1;
      }
  
      @JsonProperty("prop2")
      public Integer getProp2() {
          return prop2;
      }
  
      @JsonProperty("prop2")
      public void setProp2(Integer prop2) {
          this.prop2 = prop2;
      }
  
      @JsonProperty("proop3")
      public Integer getProop3() {
          return proop3;
      }
  
      @JsonProperty("proop3")
      public void setProop3(Integer proop3) {
          this.proop3 = proop3;
      }
  
      @Override
      public String toString() {
          return "A [type=" + type + ", prop1=" + prop1 + ", prop2=" + prop2 + ", proop3=" + proop3 + "]";
      }
  }
  </code></pre>
  
  <p><br/><br/>
  Class B<br/></p>
  
  <pre><code>public class B {
  
      @JsonProperty("type")
      private String type;
      @JsonProperty("prop1")
      private Integer prop1;
      @JsonProperty("prop2")
      private Integer prop2;
      @JsonProperty("proop3")
      private Integer proop3;
  
      @JsonProperty("type")
      public String getType() {
          return type;
      }
  
      @JsonProperty("type")
      public void setType(String type) {
          this.type = type;
      }
  
      @JsonProperty("prop1")
      public Integer getProp1() {
          return prop1;
      }
  
      @JsonProperty("prop1")
      public void setProp1(Integer prop1) {
          this.prop1 = prop1;
      }
  
      @JsonProperty("prop2")
      public Integer getProp2() {
          return prop2;
      }
  
      @JsonProperty("prop2")
      public void setProp2(Integer prop2) {
          this.prop2 = prop2;
      }
  
      @JsonProperty("proop3")
      public Integer getProop3() {
          return proop3;
      }
  
      @JsonProperty("proop3")
      public void setProop3(Integer proop3) {
          this.proop3 = proop3;
      }
  
      @Override
      public String toString() {
          return "B [type=" + type + ", prop1=" + prop1 + ", prop2=" + prop2 + ", proop3=" + proop3 + "]";
      }
  }
  </code></pre>
  
  <p><br/><br/> 
  Main Class<br/></p>
  
  <pre><code>@SpringBootApplication
  @ComponentScan(basePackages = {"com.microservice.*"})
  @EnableJpaRepositories("com.microservice.*")
  @EntityScan("com.microservice.*")
  public class MainApplication {  
      public static void main(String[] args) {
           SpringApplication app = new SpringApplication(MainApplication.class);
              app.run();
              System.out.println("step 1");
              Demo config = new Demo();
              System.out.println("name: " + config);
          }
  
          public void run(String... args) throws Exception {
              System.out.println("step 2");
  
          }
  }
  </code></pre>
  
  <p>But I am getting below o/p:
  <br/>
  <strong>step 1 <br/>
  name: Demo [a=null, b=null]<br/></strong></p>