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(){
}
}