美文网首页
【spring-test】spring-test @Rollba

【spring-test】spring-test @Rollba

作者: giraffecode9668 | 来源:发表于2019-05-28 14:26 被阅读0次

2019-05-28
如果使用spring-test进行单元测试,它会自动回滚即@Rollback(value = true)
但是我在使用过程无论value为true/false,它都无作用
最后,因为spring没有取得事务控制,即aop没有,不能执行回滚

最后在配置文件

    <!--事务控制-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--控制数据源-->
        <property name="dataSource" ref="pooledDataSource"/>
    </bean>
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:config/spring-context.xml"})
public class MapperTest {

    @Autowired
    WardenMapper wardenMapper;

    @Autowired
    StudentMapper studentMapper;

    /**
     * 测试Mapper
     */
    @Test
    @Transactional
    @Rollback(value = false)
    public void testCRUD(){

    }

}

相关文章

网友评论

      本文标题:【spring-test】spring-test @Rollba

      本文链接:https://www.haomeiwen.com/subject/buqdtctx.html