applicationContext.xml 中 关于配置ibatis事务管理部分代码
<!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 管理事务操作 --> <aop:config> <aop:pointcut id="servicesPointcut" expression_r_r="execution(* cn.com.jiexun.dao.impl.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="servicesPointcut" /> </aop:config> <!-- 事务控制 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="get*" read-only="true" /> </tx:attributes> </tx:advice> <aop:pointcut id="servicesPointcut" expression_r_r="execution(* cn.com.jiexun.dao.impl.*.*(..))" />
--------------------------------------
我是将事务代理指向了实现类(指向service层也是没有问题的),注意:千万不要在此方法中加try/catch,否则事务将不会自动回滚