title: Spring @ConfigurationProperties binding fails in test
body: <p>I'm trying to load influxDB properties from application.yml in a test.</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @EnableConfigurationProperties(InfluxDBProperties.class)
  public class StupidRepoIntegrationTest {
      @Autowired
      public InfluxDBProperties properties;
  
      @Test
      public void test() {
          System.out.println(stringify.apply(properties));
      }
  
      static Function&lt;InfluxDBProperties, String&gt; stringify = new Function&lt;InfluxDBProperties, String&gt;() {
          @Override
          public String apply(InfluxDBProperties influxDbProperties) {
              StringBuilder sb = new StringBuilder("InfluxDBProperties: [");
  
              sb.append("Url=").append(influxDbProperties.getUrl()).append(", ");
              sb.append("Database=").append(influxDbProperties.getDatabase()).append(", ");
              sb.append("Username=").append(influxDbProperties.getUsername()).append(", ");
              sb.append("Password=").append(influxDbProperties.getPassword()).append(", ");
              sb.append("RetentionPolicy=").append(influxDbProperties.getRetentionPolicy()).append(", ");
              sb.append("ConnectTimeout=").append(influxDbProperties.getConnectTimeout()).append(", ");
              sb.append("ReadTimeout=").append(influxDbProperties.getReadTimeout()).append(", ");
              sb.append("WriteTimeout=").append(influxDbProperties.getWriteTimeout()).append(", ");
              sb.append("GzipEnabled=").append(influxDbProperties.isGzip()).append("]");
  
              return sb.toString();
          }
      };
  }
  </code></pre>
  
  <p>I have application.yml, as well as application-test.yml and application-integrationTest.yml that looks as follows:</p>
  
  <pre><code>spring:
    influxdb:
      url: http://localhost:8086
      username: admin
      password: adminPass
      database: integrationTest
      retention-policy: autogen
      connect-timeout: 10
      read-timeout: 30
      write-timeout: 10
      gzip: true
  </code></pre>
  
  <p>When executing the test, I get the following exception:</p>
  
  <pre><code>java.lang.IllegalStateException: Failed to load ApplicationContext
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
      at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
      at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
      at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
      at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
      ...
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.influxdb-org.springframework.data.influxdb.InfluxDBProperties': Could not bind properties to InfluxDBProperties (prefix=spring.influxdb, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.validation.BindException: org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanPropertyBindingResult: 4 errors
  Field error in object 'spring.influxdb' on field 'username': rejected value [null]; codes [NotEmpty.spring.influxdb.username,NotEmpty.username,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.influxdb.username,username]; arguments []; default message [username]]; default message [may not be empty]
  Field error in object 'spring.influxdb' on field 'url': rejected value [null]; codes [NotEmpty.spring.influxdb.url,NotEmpty.url,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.influxdb.url,url]; arguments []; default message [url]]; default message [may not be empty]
  Field error in object 'spring.influxdb' on field 'database': rejected value [null]; codes [NotEmpty.spring.influxdb.database,NotEmpty.database,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.influxdb.database,database]; arguments []; default message [database]]; default message [may not be empty]
  Field error in object 'spring.influxdb' on field 'retentionPolicy': rejected value [null]; codes [NotEmpty.spring.influxdb.retentionPolicy,NotEmpty.retentionPolicy,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.influxdb.retentionPolicy,retentionPolicy]; arguments []; default message [retentionPolicy]]; default message [may not be empty]
      ...
      ... 48 common frames omitted
  Caused by: org.springframework.validation.BindException: org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanPropertyBindingResult: 4 errors
  Field error in object 'spring.influxdb' on field 'username': rejected value [null]; codes [NotEmpty.spring.influxdb.username,NotEmpty.username,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.influxdb.username,username]; arguments []; default message [username]]; default message [may not be empty]
  Field error in object 'spring.influxdb' on field 'url': rejected value [null]; codes [NotEmpty.spring.influxdb.url,NotEmpty.url,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.influxdb.url,url]; arguments []; default message [url]]; default message [may not be empty]
  Field error in object 'spring.influxdb' on field 'database': rejected value [null]; codes [NotEmpty.spring.influxdb.database,NotEmpty.database,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.influxdb.database,database]; arguments []; default message [database]]; default message [may not be empty]
  Field error in object 'spring.influxdb' on field 'retentionPolicy': rejected value [null]; codes [NotEmpty.spring.influxdb.retentionPolicy,NotEmpty.retentionPolicy,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.influxdb.retentionPolicy,retentionPolicy]; arguments []; default message [retentionPolicy]]; default message [may not be empty]
      at org.springframework.boot.bind.PropertiesConfigurationFactory.checkForBindingErrors(PropertiesConfigurationFactory.java:359)
      at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:276)
      at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:240)
      at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:329)
      ... 66 common frames omitted
  </code></pre>
  
  <p>What should I change to make spring pick up config in test runs?</p>