title: Spring:failed to load applicationContext?
body: <p>My project has <code>service</code> module which has <code>applicationContext.xml</code> on <code>src/main/resources</code> path.  </p>
  
  <p>I run integration test using <code>maven-cargo</code> plugin and dependency looks like  </p>
  
  <pre><code>            &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.cargo&lt;/groupId&gt;
                  &lt;artifactId&gt;cargo-maven2-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.4.8&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;container&gt;
                          &lt;containerId&gt;tomcat7x&lt;/containerId&gt;
                          &lt;systemProperties&gt;
                              &lt;spring.profiles.active&gt;${spring.profiles.active}&lt;/spring.profiles.active&gt;
                          &lt;/systemProperties&gt;
                          &lt;dependencies combine.children="append"&gt;
                              &lt;dependency&gt;
                                  &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
                                  &lt;artifactId&gt;derby&lt;/artifactId&gt;
                              &lt;/dependency&gt;
                              &lt;dependency&gt;
                                  &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
                                  &lt;artifactId&gt;derbyclient&lt;/artifactId&gt;
                              &lt;/dependency&gt;
                          &lt;/dependencies&gt;
                          &lt;!--&lt;logLevel&gt;warn&lt;/logLevel&gt;--&gt;
                      &lt;/container&gt;
                      &lt;configuration&gt;
                          &lt;properties&gt;
                              &lt;cargo.servlet.port&gt;9090&lt;/cargo.servlet.port&gt;
                              &lt;cargo.datasource.datasource.derby&gt;cargo.datasource.driver=org.apache.derby.jdbc.ClientDriver
                                  cargo.datasource.url=jdbc:derby://localhost:1527/pryme_common;create=true|
                                  cargo.datasource.username=sa|&lt;/cargo.datasource.datasource.derby&gt;
                          &lt;/properties&gt;
                      &lt;/configuration&gt;
                      &lt;deployables&gt;
                          &lt;deployable&gt;
                              &lt;groupId&gt;com.org.common&lt;/groupId&gt;
                              &lt;artifactId&gt;services&lt;/artifactId&gt;
                              &lt;type&gt;war&lt;/type&gt;
                              &lt;properties&gt;
                                  &lt;context&gt;common&lt;/context&gt;
                              &lt;/properties&gt;
                          &lt;/deployable&gt;
                      &lt;/deployables&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;start-container&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;start&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;stop-container&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;stop&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;phase&gt;post-integration-test&lt;/phase&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  </code></pre>
  
  <p>I run my integration test as  </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = "classpath:applicationContext.xml")
  public class ITCache extends AbstractIntegrationTest {
  
      @Autowired
      private ApplicationContext applicationContext;
  
      @Test
      public void testCaches() {
          {
              final String url = "http://localhost:9090/common/rest";
              final Client client = ClientBuilder.newClient();
              final WebTarget target = client.target(url).path("networks");
              final Invocation.Builder builder = target.request().accept(MediaType.APPLICATION_JSON);
              final Response response = builder.get();
              assertStatus(Response.Status.OK.getStatusCode(), response);
          }
          assertNotNull(applicationContext);
          final SimpleCacheManager simpleCacheManager = (SimpleCacheManager) applicationContext.getBean("cacheManager");
          System.out.println("cacheName:" + simpleCacheManager.getCacheNames().toString());
          System.out.println(simpleCacheManager.getCache("genders").toString());
      }
  }
  </code></pre>
  
  <p>and I see error as  </p>
  
  <pre><code>Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.018 sec &lt;&lt;&lt; FAILURE!
  testCaches(com.org.comma.integration.ITCache)  Time elapsed: 0.016 sec  &lt;&lt;&lt; ERROR!
  java.lang.IllegalStateException: Failed to load ApplicationContext
          at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
          at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
          at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
          at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
          at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:319)
          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212)
          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:232)
          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
          at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
          at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
          at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
          at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:236)
          at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134)
          at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:606)
          at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
          at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
          at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
          at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
          at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
  Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
          at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
          at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
          at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
          at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
          at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
          at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)
          at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:235)
          at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:118)
          at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
          at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
          at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
          at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
          at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
          ... 31 more
  Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
          at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
          at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
          ... 43 more
  </code></pre>
  
  <p>Although I do see that file  </p>
  
  <pre><code>$jar -tvf integration/target/cargo/configurations/tomcat7x/webapps/common.war | grep app     
    2342 Wed Jul 16 16:16:10 PDT 2014 WEB-INF/classes/applicationContext.xml
  </code></pre>