求 Spring3 + ibatis3 事务管理方案
使用 Spring3 版本, ibatis3 版本,
如何集成,并做声明式事务。
另外,如何做分布式,可得分。
[解决办法]
你手动写你的事务管理,写一个通知,在事前通知里开启事务,事后通知关闭事务,异常里面回滚,然后用模糊匹配,使用规则的命名,应该是可以做的。因为我没用过ibatis3,所以不好说,我原来做过hibernate使用sessionFactory的注入时候,这样处理过事务,因为spring没有对sessionFactory的事务处理
[解决办法]
在Spring配置文件中配置事务的传播特性需要配置advice及事务的切面aop和切入点<bean id="transactionManager"//事务管理器 class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean>事务传播特性 <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/>add开头的方法,配置事务管理 <tx:method name="delete*" propagation="REQUIRED" />对delete开头的方法,进行事务管理 <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="*" read-only="true" />其他方法只读,一般指查询方法。就不需要事务 </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="allManagerMethod" expression="execution(* com.hoo.service.*.*(..))" />//对com.hoo.service包下的所有类 所以方法 进行过滤(也就是事务管理) <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" /> </aop:config>
[解决办法]