title: Integration Test - Could not Open ServletContext Resource /application.properties
body: <p>I have 2 <code>.properties</code> files. One is the standard one, the second one is for private values e.g. email username, password etc....</p>
  
  <p>Integration test throws an error saying it can't open <code>/application.properties</code></p>
  
  <p>PortalApplication: </p>
  
  <pre><code>@SpringBootApplication(scanBasePackages = {"com.portal"})
  @PropertySources({
          // global property file
          @PropertySource("application.properties"),
          // local property file that I store personal properties e.g.: mail username &amp; password.
          @PropertySource("application-local.properties")
  })
  public class PortalApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(PortalApplication.class, args);
  
      }
  }
  </code></pre>
  
  <p>If I comment out the <code>@PropertySources()</code>, the test runs. Is there a way to run the integration test without commenting <code>@PropertySources()</code>?</p>
  
  <p>error: </p>
  
  <pre><code>java.lang.IllegalStateException: Failed to load ApplicationContext
  
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
      at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:107)
      at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
      at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
      at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:242)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.portal.PortalApplication]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/application.properties]
      at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:180)
      at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316)
      at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
      at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)
      at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
      at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
      at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:138)
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
      ... 24 more
  Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/application.properties]
      at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:159)
      at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:159)
      at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:99)
      at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:73)
      at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:59)
      at org.springframework.core.io.support.ResourcePropertySource.&lt;init&gt;(ResourcePropertySource.java:67)
      at org.springframework.core.io.support.DefaultPropertySourceFactory.createPropertySource(DefaultPropertySourceFactory.java:37)
      at org.springframework.context.annotation.ConfigurationClassParser.processPropertySource(ConfigurationClassParser.java:446)
      at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:268)
      at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:241)
      at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
      at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:166)
      ... 36 more
  </code></pre>