日期:2014-05-19 浏览次数:20658 次
public boolean insertTxTest() { try {// 添加异常捕获 事务不能回滚 name 是主键,不添加异常捕获 事务正常回滚。 UserBean userBean = new UserBean(); userBean.setName("张三"); userBean.setPw("123456"); getSqlMapClientTemplate().insert("tx.insert",userBean); getSqlMapClientTemplate().insert("tx.insert",userBean); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
<!-- 事务处理器 --> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <value>txTestDao</value> </list> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED,-Exception</prop> </props> </property> </bean>