為什么沒有把事務(wù)綁定在一起 ,第一個(gè)還是修改了
@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);
}
}<!-- 將事務(wù)與mySql關(guān)聯(lián) -->
? ? <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
? ? ? ? <property name="dataSource" ref="dataSource" />
? ? </bean>
? ??
? ? <!-- 事務(wù)注解驅(qū)動(dòng),標(biāo)注@Transactional的類和方法將具有事務(wù)性 -->
? ? <tx:annotation-driven transaction-manager="transactionManager"/>
2015-09-09
applicationContext.xml
dispatcher-servlet.xml
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); } }已解決。都沒人回復(fù)我 ?好失望。。。
2015-09-08
springMVC + mybits + mysql