spring mvc 事务
applicationContext.xml:
<context:component-scan base-package="com.ssh,com" >
</context:component-scan>
springMvc-servlet.xml
<context:component-scan base-package="com.ssh,com" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
服务类: @Transactional(rollbackFor=Exception.class) ,若没配,则无事务。在接口配置,也无事务。服务类非接口方法也无事务,如private
// @Transactional(rollbackFor=Exception.class) public void testRollback() throws Exception{ //插入数据1 TBatTaskLog bean = new TBatTaskLog(); bean.setBatchNo("11111"); bean.setBranchNo("11111"); bean.setCreateTime(new Date()); bean.setCreator("a"); bean.setInstanceId("111111111"); bean.setMessage("abc"); bean.setSeqNo(5); hbmBaseDao.save(bean); LogUtil.println("a#####################1"); //插入数据2 TBatInstPre beanpre = new TBatInstPre(); beanpre.setInstanceId("111111111"); beanpre.setPreInstanceId("aaaaaaaaaaa"); this.hbmBaseDao.save(beanpre); LogUtil.println("a#####################2");
//抛异常
throw new Exception("abccc");
}