请问,spring 是否能进行分布式事务管理?如果能的话能否举一个例子。
还有,除了EJB外,进行分布式事务管理还有什么好的方式没有,小弟不是很了解EJB。

解决方案 »

  1.   

    我觉得可以吧,你说的分布式事务是指跨越多个数据源的事务吧。
    在Spring里提供了声明式事务,所以可以通过JTA实现分布式事务。
      

  2.   

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <bean id="hibTxManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean> <!-- 事物传播特性-->
    <tx:advice id="txAdvice" transaction-manager="hibTxManager">
    <tx:attributes>
    <tx:method name="save*" read-only="true" />
    <tx:method name="del*" read-only="true" />
    <tx:method name="search" read-only="true" />

    <tx:method name="*" propagation="REQUIRED"/>
    </tx:attributes>
    </tx:advice> <!--  事物传播到方法-->
    <aop:config>
    <aop:pointcut id="bizMethods"
    expression="execution(* cn.com.yyaccp.service.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
    </aop:config></beans>