title: Spring Boot Configuration Not Working
body: <p>I'm using Spring boot.</p>
  
  <p>I have an <code>application.yml</code> in <code>src/main/resources</code>.  I then have a Configuration class that I am trying to get to load the <code>application.yml</code>.  However, when I try to use the configuration class in another bean, the values are null.  See the <code>ApiHelper.java</code> as to where the values are null.</p>
  
  <p>I'm attempting to run the jar as so:</p>
  
  <pre><code>java -jar build/libs/app.jar
  </code></pre>
  
  <p>Am I doing something wrong?  I've also tried using a properties file instead.  When I unzip the jar file the configuration files are in the root.</p>
  
  <p><strong>src/main/resources/application.yml</strong></p>
  
  <pre><code>spring: 
      profiles.active: default
  ---
  spring:
     profiles: default
  api:
     path: http://some-path
  ---
  spring:
     profiles: qa
  api:
     path: http://some-path2
  </code></pre>
  
  <p><strong>src/main/java/AppConfig.java</strong></p>
  
  <pre><code>@Configuration
  @EnableConfigurationProperties(ApiConfig.class)
  public class AppConfig {
      @Autowired
      private ApiConfig apiConfig;
  
      @ConfigurationProperties(value = "api", exceptionIfInvalid=true)
      public static class ApiConfig {
          private String path;
  
          public ApiConfig() {
              System.out.println("Am I getting called?");  // yes it is
          }
  
          public String getPath() {
              return path;
          }
      }
  
      @Bean
      public ApiHelper getApiHelper() {
          return new ApiHelper();
      }
  }
  </code></pre>
  
  <p><strong>src/main/java/ApiHelper.java</strong></p>
  
  <pre><code>public class ApiHelper {
      @Autowired
      private ApiConfig apiConfig;
  
      @PostConstruct
      private void init() {
          System.out.println(apiConfig); // prints ApiConfig@168498d6
          System.out.println(apiConfig.getPath()); // prints null
      }
  }
  </code></pre>