title: Using Spring Boot 1.2 YAML configuration
body: <p>I have an application with Spring Boot 1.2 and I need to use YAML configuration.
  I tried following settings:</p>
  <p><strong>pom.xml</strong></p>
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.2.0.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt;
  &lt;/parent&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      
      &lt;plugin&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
      &lt;/plugin&gt;
  </code></pre>
  <p><strong>application.yml</strong></p>
  <pre><code>foo:
    bar: baz
  </code></pre>
  <p><strong>FooProperties</strong></p>
  <pre><code>@Configuration
  @ConfigurationProperties(prefix = &quot;foo&quot;)
  public class FooProperties {
  
    private String bar;
    
    // getters, setters, equals etc.
  </code></pre>
  <p><strong>FooPropertiesConfig</strong></p>
  <pre><code>@Configuration
  @EnableConfigurationProperties(FooProperties.class)
  public class FooPropertiesConfig {
  }
  </code></pre>
  <p><strong>FooPropertiesTest</strong></p>
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = FooProperties.class)
  @EnableConfigurationProperties(value = FooProperties.class)
  @TestPropertySource(&quot;classpath:application.yml&quot;)
  public class FooPropertiesTest extends TestCase {
  
      @Autowired
      private FooProperties tested;
  
      @Test
      public void test() {
          final String bar = tested.getBar();
  
          assertEquals(&quot;baz&quot;, bar);
      }
  }
  </code></pre>
  <p>But <em>bar</em> is always null. What am I missing?</p>
  <p>EDIT1:
  I tried to use old-fashion <em>application.properties</em> but the result is the same.</p>
  <p>EDIT2:</p>
  <p>I've created endpoint and it works. Problem seems to be only in my test configuration.</p>
  <pre><code>@RestController
  public class FooController {
  
      @Autowired
      private FooProperties fooProperties;
  
      @RequestMapping(&quot;/&quot;)
      String foo() {
          return &quot;Hello World: &quot; + fooProperties.getBar();
      }
  }
  </code></pre>
  <p><strong>Result:</strong> Hello World: baz</p>