Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 插入弹簧测试后的回滚_Java_Spring Mvc_Testing - Fatal编程技术网

Java 插入弹簧测试后的回滚

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; @

我正在对我的spring应用程序进行测试,在测试应用程序的同时将数据插入db。 但我不知道如何回退

测试代码:

@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" />