Java 插入弹簧测试后的回滚
我正在对我的spring应用程序进行测试,在测试应用程序的同时将数据插入db。 但我不知道如何回退 测试代码:Java 插入弹簧测试后的回滚,java,spring-mvc,testing,Java,Spring Mvc,Testing,我正在对我的spring应用程序进行测试,在测试应用程序的同时将数据插入db。 但我不知道如何回退 测试代码: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:/META-INF/spring.cfg.xml") public class SpringAppTest{ @Autowired private MyService myService; @
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/META-INF/spring.cfg.xml")
public class SpringAppTest{
@Autowired
private MyService myService;
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Test
public void testInsert(){
//insert code
}
}
请引导我。上课前使用以下注释:
@TransactionConfiguration(transactionManager = "txManager",defaultRollback = true)
@Transactional
这里txManager是应用程序上下文的事务管理器
这里txManager是应用程序上下文中事务管理器的实例或bean id
<!-- Transaction Manager -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />