title: Spring Boot: custom properties configuration and tests
body: <p>I'm using Spring Boot 2.0 with default <code>application.yml</code> properties file. I would like to split it to separate property files because it becomes huge.<br>
  Also I would like to write tests to check properties correctness: values that will present on production application context (not the test one).</p>
  
  <p>Here is my property file: <strong>src/main/resources/config/custom.yml</strong></p>
  
  <pre><code>my-property:
    value: 'test'
  </code></pre>
  
  <p>Property class:</p>
  
  <pre><code>import lombok.Data;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  
  @Data
  @Configuration
  @ConfigurationProperties(prefix = "my-property")
  @PropertySource("classpath:config/custom.yml")
  public class MyProperty {
  
    private String value;
  }
  </code></pre>
  
  <p>Test:</p>
  
  <pre><code>import static org.junit.Assert.assertEquals;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.context.properties.EnableConfigurationProperties;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.test.context.junit4.SpringRunner;
  
  @RunWith(SpringRunner.class)
  @SpringBootTest(classes = MyProperty.class)
  @EnableConfigurationProperties
  public class MyPropertyTest {
  
    @Autowired
    private MyProperty property;
  
    @Test
    public void test() {
      assertEquals("test", property.getValue());
    }
  
  }
  </code></pre>
  
  <p>But test fails with error:</p>
  
  <pre><code>java.lang.AssertionError: 
  Expected :test
  Actual   :null
  </code></pre>
  
  <p>Also I see that property value is <code>null</code> when running the application by printing it in <code>ApplicationRunner</code>.<br>
  When I used <code>application.yml</code> for all properties it were well with the same configuration.  </p>
  
  <p>How to put correct configuration for properties and tests for make it work?<br>
  Link to <a href="https://github.com/bullet-tooth/spring-custom-properties" rel="nofollow noreferrer">Github repo</a></p>