http://stackoverflow.com/questions/734614/spring-hibernate-junit-no-hibernate-session-bound-to-thread
Wrong, that will just fill your code with session management code.
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
If your transaction demarcation is correct(surrounding your dao or service) you should be done.
It's not nice to sprinkle session and transaction handling code all around your code (even inside your tests).
Spring Hibernate JUnit 测试

本文介绍了如何在Spring和Hibernate环境中使用JUnit进行正确的事务管理。首先需要在上下文中添加事务管理bean,然后继承AbstractTransactionalJUnit4SpringContextTests类,并使用@TransactionConfiguration和@Transactional注解来配置测试类。
2878

被折叠的 条评论
为什么被折叠?



