title: WebAppConfiguration doesn't play well with ContextConfiguration?
body: <p>I have an existing Java app using Spring MVC 3.2.1.   The existing unit tests all work fine.   Now I'm trying to a new unit test, using the @WebAppConfiguration annotation for the first time, and it's blowing up with a wacky error.   </p>
  
  <p>Here's my new unit test, taken almost verbatim from <a href="https://spring.io/blog/2012/11/12/spring-framework-3-2-rc1-spring-mvc-test-framework" rel="nofollow">this page</a>:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @WebAppConfiguration
  @ContextConfiguration(locations={"classpath:war-test-context.xml"})
  @Transactional
  public class GenericPageControllerTest {
  
      @Autowired
      private WebApplicationContext webApplicationContext;
  
      private MockMvc mockMvc;
  
      @Before
      public void setup() {
          this.mockMvc = webAppContextSetup(this.webApplicationContext).build();
      }
  
      @Test
      public void testControllerSecurityTestThingyTestWithALongNameTest() throws Exception {
          this.mockMvc.perform(get("/payOptions.html"))
          .andExpect(redirectedUrl("/login.html"));
      }
  
  }
  </code></pre>
  
  <p>Here's the error I'm getting:</p>
  
  <pre><code>java.lang.IllegalStateException: Failed to load ApplicationContext
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [war-test-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [war-test-context.xml]: Cannot resolve reference to bean 'persistenceUnitManager' while setting bean property 'persistenceUnitManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceUnitManager' defined in class path resource [war-test-context.xml]: Cannot resolve reference to bean 'caDataSource' while setting bean property 'dataSources' with key [TypedStringValue: value [caDataSource], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'caDataSource': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from ServletContext resource [/database/myapp_schema.sql]
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [war-test-context.xml]: Cannot resolve reference to bean 'persistenceUnitManager' while setting bean property 'persistenceUnitManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceUnitManager' defined in class path resource [war-test-context.xml]: Cannot resolve reference to bean 'caDataSource' while setting bean property 'dataSources' with key [TypedStringValue: value [caDataSource], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'caDataSource': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from ServletContext resource [/database/myapp_schema.sql]
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceUnitManager' defined in class path resource [war-test-context.xml]: Cannot resolve reference to bean 'caDataSource' while setting bean property 'dataSources' with key [TypedStringValue: value [caDataSource], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'caDataSource': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from ServletContext resource [/database/myapp_schema.sql]
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'caDataSource': Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from ServletContext resource [/database/myapp_schema.sql]
  Caused by: org.springframework.dao.DataAccessResourceFailureException: Failed to populate database; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from ServletContext resource [/database/myapp_schema.sql]
  Caused by: org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from ServletContext resource [/database/myapp_schema.sql]
  Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/database/myapp_schema.sql]
  </code></pre>
  
  <p>Other tests using just the <code>@ContextConfiguration</code> annotation find this file and instantiate this bean just fine.    Can anyone tell me why the <code>@WebAppConfiguration</code> bean is making it throw up?   Here's the configuration section it's telling me won't work:  </p>
  
  <pre><code>&lt;jdbc:embedded-database id="caDataSource" type="HSQL"&gt;
      &lt;jdbc:script location="database/myapp_schema.sql"/&gt;
      &lt;jdbc:script location="database/myapp_data.sql"/&gt;
  &lt;/jdbc:embedded-database&gt;
  </code></pre>
  
  <p>The files are on the classpath, but they're in a different project - that might be the only wrinkle.   Anyone got any ideas, or handy links?</p>