假象
2015-09-08 16:05
@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"/>
applicationContext.xml
<tx:annotation-driven /> <context:component-scan base-package="com.code" />
dispatcher-servlet.xml
<context:component-scan base-package="com.code" > <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> </context:component-scan>
package com.code.service.impl; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.code.dao.TestDAO; import com.code.entity.Test; import com.code.service.TestService; @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); } }
已解决。都没人回复我 好失望。。。
springMVC + mybits + mysql
Spring事务管理
87318 学习 · 197 问题
相似问题