title: Can't inject DAO in Junit test with Spring
body: <p>I'm trying to use HSQL in-memory database with my Junit tests. I have an entity model:</p>
  
  <pre><code>package com.project.model.db;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="users")
  public class User {
  
   @Id
   @GeneratedValue
   private Integer id;
       ...
  </code></pre>
  
  <p>And a DAO</p>
  
  <pre><code>package com.project.dao.impl;
  ...
  
  @Repository
  public class UserDaoImpl
  ...
  </code></pre>
  
  <p>My test context (under src/test/resources/test-context.xml) in full is:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans     
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.2.xsd
      http://www.springframework.org/schema/jdbc
      http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"&gt;
  
  &lt;context:component-scan base-package="com.project" /&gt;
  
  &lt;jdbc:embedded-database id="dataSource" type="HSQL" /&gt;
  
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="packagesToScan" value="com.project" /&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;com.project.model.db.User&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven /&gt;
  </code></pre>
  
  <p></p>
  
  <p>And my test class is:</p>
  
  <pre><code>package com.project.dao.impl;
  
  import javax.inject.Inject;
  import com.project.model.db.User;
  ...
  @RunWith(MockitoJUnitRunner.class)
  @ContextConfiguration({ "classpath:/test-context.xml" })
  @DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
  public class UserDaoImplTest {
  
  @Inject private UserDaoImpl userDaoImpl;
  
  @Test
  public void savesUser() {
      ....
  </code></pre>
  
  <p>But when I run the test, I get a null pointer exception for the injected UserDaoImpl.  I don't know why this is?</p>