title: Spring jUnit Testing - either can not autowire or can not find appContext.xml
body: <p>I am unittesting a spring based application atm. 
  First the problem is, that if I haven't started the app once on a server the unittests all fail.
  If I do start the app on the server first (and stop it), my unit tests are working.</p>
  
  <p>Without starting the server I get the following error:</p>
  
  <pre><code>... java.io.FileNotFoundException: class path resource [META-INF/spring/applicationContext-test.xml] cannot be opened because it does not exist
  </code></pre>
  
  <p>My Unit test is defined as following:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = { "/META-INF/spring/applicationContext-test.xml" })
  @TransactionConfiguration
  @Transactional
  public class InventoryControllerTest extends AbstractTransactionalJUnit4SpringContextTests {
  
      private MockHttpServletRequest request;
      private MockHttpServletResponse response;
  
      private AnnotationMethodHandlerAdapter handlerAdapter;
  
      @Before
      public void setUp() throws Exception {
          request = new MockHttpServletRequest();
          response = new MockHttpServletResponse();
          handlerAdapter = applicationContext
              .getBean(AnnotationMethodHandlerAdapter.class);
  }
      //... tests
  }
  </code></pre>
  
  <p>So like I said, if I've started the app once before, everything works fine.</p>
  
  <p>So I changed the configuration location to 
      locations = { "classpath/META-INF/spring/applicationContext-test.xml" })
  But without effort, same exception as named above.</p>
  
  <p>The only way to get further is this location:
      locations = { "classpath*:applicationContext-test.xml" })
  Then I get this exception:
      No matching bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}</p>
  
  <p>But that's confusing, because I definetly have a datasource in my test context file:</p>
  
  <pre><code>&lt;bean class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close" id="dataSource"&gt;
      &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver" /&gt;
      &lt;property name="url" value="jdbc:hsqldb:mem:testdb;sql.syntax_ora=true" /&gt;
      &lt;property name="username" value="some" /&gt;
      &lt;property name="password" value="some" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <h2>EIDT 2</h2>
  
  <p>After recognizing, that the problem is RunWith(...) and extending the spring class at the same time and removing all wildcards from the location path. I get this exception:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [META-INF/spring/applicationContext-test.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/spring/applicationContext-test.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'persistenceUnitTest' found
  ... 24 more
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/spring/applicationContext-test.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'persistenceUnitTest' found
  ... 40 more
  Caused by: java.lang.IllegalArgumentException: No persistence unit with name 'persistenceUnitTest' found)
  ... 47 more
  </code></pre>
  
  <p>I would really appreciate any help!</p>
  
  <p>Thanks in advance</p>