title: Why is @PropertySource not used when application.properties is present?
body: <p>The situation I'm in requires a file with some properties (eventually containing a list of ID's and Email addresses) to be mapped to a HashMap. In Spring I found that a properties file can be mapped to an object with <code>@ConfigurationProperties</code> and <code>@PropertySource</code>. To test this mechanism, I created a test project, but <code>@PropertySource</code> seems to be ignored when default <code>application.properties</code> file exists. I'm wondering how this is possible and how I can solve it so that it uses the properties file specified.</p>
  
  <p><strong>Application.java</strong></p>
  
  <pre><code>@SpringBootApplication
  @EnableConfigurationProperties
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p><strong>DemoProperties.java</strong></p>
  
  <pre><code>@Component
  @Configuration
  @ConfigurationProperties("test")
  @PropertySource("classpath:test.properties")
  public class DemoProperties {
      private String name;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p><strong>test.properties</strong></p>
  
  <pre><code>test.name=myNameGood
  </code></pre>
  
  <p><strong>application.properties</strong></p>
  
  <pre><code>test.name=myNameBad
  </code></pre>
  
  <p><strong>ApplicationTests.java</strong></p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  public class ApplicationTests {
  
      @Autowired
      DemoProperties demoProperties;
  
      @Test
      public void contextLoads() {
          System.out.println(demoProperties.getName());
      }
  
  }
  </code></pre>
  
  <p>So this Test prints <code>myNameBad</code> when <code>application.properties</code> is present, but when I delete or rename that file, the output is <code>myNameGood</code> (which is desired).</p>