spring的事務控制配置

      通常我們web系統中需要事物控制,可以通過spring容器來進行。下面部分配置簡單的說明了spring的事物控制。我們可以給applicationContext-common.xml文件中添加如下代碼,實現事物的控制:

      <bean id="transactionManager"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
 </bean>

 <tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="save*" propagation="REQUIRED" />
   <tx:method name="del*" propagation="REQUIRED" />
   <tx:method name="update*" propagation="REQUIRED" />
   <tx:method name="submit*" propagation="REQUIRED" />    
   <tx:method name="dispatch*" propagation="REQUIRED" />    
   <tx:method name="undispatch*" propagation="REQUIRED" />    
   <tx:method name="send*" propagation="REQUIRED" />    

   <tx:method name="*" read-only="true" />
  </tx:attributes>
 </tx:advice>

 <aop:config>
  <aop:pointcut id="allManagerMethod"
   expression="execution(* cn.com.test.service.impl.*.*.*(..))" />
  <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
 </aop:config>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章