spring中事务管理

来源:互联网 发布:微信群一键加人软件 编辑:程序博客网 时间:2024/06/05 17:45

在spring中,事务管理的代码一般都是如下代码:

<!-- ================================事务相关控制=================================================    -->
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>


<tx:advice id="userTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
   
  
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="select*" read-only="true" />
</tx:attributes>
</tx:advice>


<aop:config>
   <!--  (..)表示任意参数类型-->
<aop:pointcut id="pc" expression="execution(* com.njupt.service.*.*(..))" />
<!--把事务控制在Service层-->
<aop:advisor pointcut-ref="pc" advice-ref="userTxAdvice" />
</aop:config>

原创粉丝点击