为什么没有把事务绑定在一起 ,第一个还是修改了
@Service public class TestServiceImpl implements TestService{ @Resource private TestDAO testDAO; @Override @Transactional public void sql() { Test t1 = new Test(); t1.setId(1L); t1.setNum(800); Test t2 = new Test(); t2.setId(2L); t2.setNum(1200); testDAO.update(t1); int bug = 1/0; testDAO.update(t2); } }
<!-- 将事务与mySql关联 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 事务注解驱动,标注@Transactional的类和方法将具有事务性 -->
<tx:annotation-driven transaction-manager="transactionManager"/>