Spring / Hibernate / JUnit - No Hibernate Session bound to Thread

在spring mvc中使用junit单元测试时,没有取到hibernate的session,修改如下:

 

First, add a transaction management bean in your context:

    <bean id="transactionManager" 
          class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
 

The second thing, extend AbstractTransactionalJUnit4SpringContextTests:

public class BaseDALTest 
           extends AbstractTransactionalJUnit4SpringContextTests{
}

 

 Third thing, annotate you test class with:

@TransactionConfiguration
@Transactional

你可能感兴趣的:(spring junit)