<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 装载属性配置文件 -->
<bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties">
<!-- <list>
<value>classpath:jdbc.properties</value>
</list>
-->
</property>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
<!-- 配置事务管理器-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="default">
<property name="dataSource" ref="dataSource"/>
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!--
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
-->
<!-- 若方法名不和下边的相同,可以修改。例如:<tx:method name="add*" propagation="REQUIRED"/> -->
<!--
1.事务传播设置是 REQUIRED
2.隔离级别是 DEFAULT
3.事务是 读/写
4.事务超时默认是依赖于事务系统的,或者事务超时没有被支持。
5.任何 RuntimeException 将触发事务回滚,但是任何 checked Exception 将不触发事务回滚
-->
<!--属性的介绍 -->
<!--
propagation属性:事务传播行为REQUIRED
I.PROPAGATION_REQUIRED:如果当前没有事务,就新建一个事务,
如果存在,加入到这个事务中------->常用
I.PROPAGATION_SUPPORTS:支持当前事务,若没有事务,就以非事务的
方式执行。
I.PROPAGATION_MANDATORY:使用当前事务,若没有事务就抛出异常。
I.PROPAGATION_REQUIRES_NEW:新建事务,若当前存在事务,把
事务挂起。
I.PROPAGATION_NOT_SUPPORTS:以非事务方式执行操作,如果当前
存在事务就挂起。
I.PROPAGATION_NEVER:以非事务的方式执行,如果当前存在事务抛出异常。
I.PROPAGATION_NESTED:如果当前存在事务,则在嵌套事务内执行。
若没有事务,则执行PROPAGATION_REQUIRED类似的操作。
isolation属性:事务隔离级别 DEFAULT
rollback-for属性: 将被触发进行回滚的 Exception(s);以逗号分开。 如:'com.foo.MyBusinessException,ServletException'
read-only属性:事务是否只读?false
-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="get*" propagation="REQUIRED" read-only="true"/>
<tx:method name="load*" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 第一个 * —— 通配 任意返回值类型
第二个 * —— 通配 包com.spring.services下的任意class
第三个 * —— 通配 包com.spring.services下的任意class的任意方法
第四个 .. —— 通配 方法可以有0个或多个参数
-->
<!--配置切入点-->
<aop:config>
<aop:pointcut id="allMethod" expression="execution(* com.spring.services.*.*(..))"/>
<aop:advisor pointcut-ref="allMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>
<!--
注意:导入commons-dbcp.jar
commons-pool.jar
-->
[/color][color=violet]
分享到:
相关推荐
Spring事务管理Demo
本代码使用H2内存数据库演示spring事务使用,包括编程式事务,声明式事务@Transactional使用,自定义事务事务注解实现自定义事务管理器
Java高级编程 实验报告 spring 声明事务 实验目的 掌握spring 声明式事务管理配置 实验环境 本实验采用本实验采用的eclipse或者 Myeclpse开发工具。Spring 4.0以上 Jdk1.7以上、oracle/mysql。
3、了解Spring事务管理的3个核心接口; 4、了解Spring事务管理的两种方式; 5、掌握基于XML和Annotation的声明式事务管理的使用。 二.实验内容 (1)使用Spring JDBC实现书店的购书过程,即有如下一个BookShopDao接口...
Spring事务管理教程,详细讲解了Spring中的事务管理,包括声明式事务,注解式事务,以及事务配置等等
Spring事务管理.pdf 1.资料 2.本地事务与分布式事务 3.编程式模型 4.宣告式模型
spring的事务管理配置详解.txt详细的描述了如何配置spring的事物。
【免费】深入描述spring的事务处理机制,很不错的资源。
spring 事务管理的理解
spring事务管理 配置文件等详解
spring3.0两种事务管理配置
自己做的一个小案例,spring 的事务管理小案例,你也可以去以下链接看文章讲解https://blog.csdn.net/zyqblog/article/details/82624441
关于spring_事务管理的一个实例,代码,全的!可以下载学习学习
spring-tx spring-transaction spring事务管理实例
在Spring中使用JTA事务管理 1 通过集成JOTM,直接在Spring中使用JTA事务 1.1. 将JOTM以下类库添加到类路径中 1.2. 编写JOTM配置文件,放到类路径下 1.3. 在MySQL上建立两个数据库 1.4. 在Spring配置文件中配置JOTM ...
Spring的事务框架将开发过程中事务管理相关的关注点进行适当的分离,并对这些关注点进行合 理的抽象,最终打造了一套使用方便,却功能强大的事务管理“利器”。通过Spring的事务框架,我 们可以按照统一的编程模型来...
Synchronized锁在Spring事务管理下,导致线程不安全。
Spring事务管理(全),需要的可下载!
3、了解Spring事务管理的3个核心接口; 4、了解Spring事务管理的两种方式; 5、掌握基于XML和Annotation的声明式事务管理的使用。 二、 实验内容 1、在MySQL中创建以下三张表,其中account为账户表,book为书籍信息...