大家讨论下平常在开发中,SSH三层框架中的事务处理(策略 || 策略+实例)。

解决方案 »

  1.   

    我一直用一个办法Spring配置文件头部改为:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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">配置内容中加上:<!-- aop事务 -->
    <!-- 建立事务管理器 -->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref local="sessionFactory" />
    </property>
    </bean>
    <!-- 定义事务通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <!-- 对查找方法进行只读事务通知要求查找方法以find开头 可按需要修改 -->
    <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
    <!-- 对其它方法如 增 删 改进行事务支持 -->
    <tx:method name="*" propagation="REQUIRED" />
    </tx:attributes>
    </tx:advice>
    <!-- 切面定义 -->
    <aop:config>
    <!-- 对cn.qdqn.biz包及子包中的任意方法进行切面 -->
    <aop:pointcut id="bizMethods"
    expression="execution(* cn.qdqn.swap.biz..*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
    </aop:config>
    over.