我已经阅读了很多关于spring事务的stackoverflow页面。 我的春季交易配置是春季交易只是在进入服务方式吗?
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
我的服务是这样的。
@Service
public class TestServiceImpl implements TestService {
@Override
public void testRollback() {
testRollbackSecondLevel();
}
@Transactional
@Override
public void testRollbackSecondLevel() {
// any update sql in here
carCostService.testUpdate();
throw new RuntimeException();
}
}
然后我写一个测试类来测试,在我的测试代码,当我使用
// this test is not roll back, and the Transactional even not created
@Test
public void testTransactional() {
// use this function, the Transactional don't work
interCityService.testRollback();
}
// this test is roll back successfully
@Test
public void testTransactionalSecondLevel() {
// but if I use the second level function instead of the first function,
// the Transactional works fine, and the data can roll back
interCityService.testRollbackSecondLevel();
}
我调试的代码,当我使用的第一个测试,交易甚至不会被创建。第二个可以成功创建事务。
我使用sql来判断事务是否存在。
SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX\G
如果sql返回空集,那么没有事务被创建。
那么问题是什么?提前致谢。
我使用春季版4.1.2.RELEASE。
我还不明白,如何改变我的代码工作?将 更改为 。它不起作用。 –
yunfan