当前位置: 代码迷 >> Java Web开发 >> struts2+spring3中applicationContext.xml中如何配置事务
  详细解决方案

struts2+spring3中applicationContext.xml中如何配置事务

热度:5070   发布时间:2013-02-25 21:22:24.0
struts2+spring3中applicationContext.xml中怎么配置事务?
使用了struts2+spring3,但是没有用hibernate。在applicationContext.xml中怎么配置transactionManager倒成了难题,网上遍寻都是SSH2的,没有单独的strtus2+spring3单独的事务配置,那就不知道后面引用的是哪个类了。
请高手不吝赐教,如果不用hibernate,事务如何配置?
XML code
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">        <property name="dataSource">            <ref local="dataSource"/>        </property>    </bean>      <bean id="txManager"        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <property name="transactionManager" ref="transactionManager" />        <property name="transactionAttributes">              <props>                 <prop key="AddOrUpdate">PROPAGATION_REQUIRED</prop>                 <prop key="Delete">PROPAGATION_REQUIRED</prop>                 <prop key="save">PROPAGATION_REQUIRED</prop>                 <prop key="update">PROPAGATION_REQUIRED</prop>                 <prop key="write">PROPAGATION_REQUIRED</prop>                 <prop key="Insert*">PROPAGATION_REQUIRED</prop>              </props>        </property>    </bean>


------解决方案--------------------------------------------------------
探讨

看清楚了再回复。我想问的是,如果没有hibernate,transactionmanager用的是哪个CLASS

------解决方案--------------------------------------------------------
org.springframework.jdbc.datasource.DataSourceTransactionManager
------解决方案--------------------------------------------------------
用事务代理拦截器,贴一段我项目中的代码:

XML code
<!-- 事务管理器 --><bean id="transactionManager"        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <property name="dataSource" ref="dataSource" /></bean><!-- 事务代理拦截器的配置 --><bean id="baseTransactionProxy" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">  <property name="transactionManager">   <ref bean="transactionManager" />  </property>  <property name="transactionAttributes">              <props>                 <prop key="AddOrUpdate">PROPAGATION_REQUIRED</prop>                 <prop key="Delete">PROPAGATION_REQUIRED</prop>                 <prop key="save">PROPAGATION_REQUIRED</prop>                 <prop key="update">PROPAGATION_REQUIRED</prop>                 <prop key="write">PROPAGATION_REQUIRED</prop>                 <prop key="Insert*">PROPAGATION_REQUIRED</prop>              </props>        </property></bean><!-- service配置 配置事务--><bean id="userService" parent="baseTransactionProxy">  <property name="target">   <bean class="com.test.service.UserService">    <property name="userDao">     <ref bean="userDao"/>    </property>   </bean>  </property></bean>
  相关解决方案