Spring的事务配置非注解方式
<!--通知-->
<tx:advice id="txAdvice" transaction-manager="txTransactionManager">
<tx:attributes>
<tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="save*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="create*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="add**" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="edit*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="modify*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="distr*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="error*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="ex*" propagation="REQUIRED" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
如果觉得麻烦的话可以这么写
<!--通知-->
<tx:advice id="txAdvice" transaction-manager="txTransactionManager">
<tx:attributes>
<tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
这样的话,除了query、select、get、find开头的没有事务之外,其他的方法都会有事务。
<!--配置切面-->
<aop:config>
<aop:pointcut id="txPointCut" expression="execution(* com.公司名..*.service..*.*(..))"></aop:pointcut>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
</aop:config>
Spring的事务的注解配置
在xml中配置
<tx:annotation-driven transaction-manager="txTransactionManager"></tx:annotation-driven>
在业务逻辑层加上注解@Transactional即可