spring聲明式事務:(還有一種是編程式事務,須要在寫代碼時本身色圖AutoCommit(false),而後本身進行commit和rollback)
<!-- ================================事務相關控制================================================= -->
51 <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
52 <property name="dataSource" ref="MyDataSource"></property>
53
54 </bean>
55
56 <tx:advice id="userTxAdvice" transaction-manager="transactionManager">
57 <tx:attributes>
58 <tx:method name="delete*" propagation="REQUIRED" read-only="false"
59 rollback-for="java.lang.Exception" no-rollback-for="java.lang.RuntimeException"/>
60 <tx:method name="insert*" propagation="REQUIRED" read-only="false"
61 rollback-for="java.lang.RuntimeException" />
62 <tx:method name="update*" propagation="REQUIRED" read-only="false"
63 rollback-for="java.lang.Exception" />
64
65
66 <tx:method name="find*" propagation="SUPPORTS"/>
67 <tx:method name="get*" propagation="SUPPORTS"/>
68 <tx:method name="select*" propagation="SUPPORTS"/>
69 </tx:attributes>
70 </tx:advice>
71
72 <aop:config>
73 <aop:pointcut id="pc" expression="execution(public * com.lixing.scm.test.service.*.*(..))" /> <!--把事務控制在Service層-->
74
75 <aop:advisor pointcut-ref="pc" advice-ref="userTxAdvice" />
76 </aop:config>
java