<?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:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 用于注解 -->
<context:annotation-config/> <!-- 方式一:基于注解声明事务:如果事务采用注解方式,就用该句 -->
<!--tx:annotation-driven transaction-manager="transactionManager"/--> <!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
<property name="username" value="lesson"/>
<property name="password" value="lesson"/>
</bean>
<!-- 实例化sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocations">
<list>
<value>classpath:hibernate.cfg.xml</value>
</list>
</property>
</bean>
<!-- 配置事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <!-- 方式二:基于xml的事务配置 开始 -->
<aop:config proxy-target-class="true">
<!-- expression(*)执行的实现类 -->
<aop:pointcut id="serviceMethods" expression="execution(* com.spring.jdbc.service.impl.UserServiceImpl.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS"/>
<tx:method name="*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 基于xml的事务配置 结束 --> <bean id="userDao" class="com.spring.jdbc.dao.impl.UserDaoImpl"></bean>
<bean id="userService" class="com.spring.jdbc.service.impl.UserServiceImpl"></bean> </beans>

spring 基于XML和注解的两种事务配置方式的更多相关文章

  1. spring 中常用的两种事务配置方式以及事务的传播性、隔离级别

    一.注解式事务 1.注解式事务在平时的开发中使用的挺多,工作的两个公司中看到很多项目使用了这种方式,下面看看具体的配置demo. 2.事务配置实例 (1).spring+mybatis 事务配置 &l ...

  2. spring 中常用的两种事务配置方式

    引用:http://blog.csdn.net/qh_java/article/details/51811533 引用:http://www.cnblogs.com/rushoooooo/archiv ...

  3. Asp.Net Core下的两种路由配置方式

    与Asp.Net Mvc创建区域的时候会自动为你创建区域路由方式不同的是,Asp.Net Core下需要自己手动做一些配置,但更灵活了. 我们先创建一个区域,如下图 然后我们启动访问/Manage/H ...

  4. 基于XML文档的声明式事务配置

    <!-- 配置事务切面 --> <aop:config> <aop:pointcut expression="execution(* com.atguigu.t ...

  5. Spring基于xml注入bean的几种方式?

    (1)Set方法注入: (2)构造器注入:①通过index设置参数的位置:②通过type设置参数类型: (3)静态工厂注入: (4)实例工厂:

  6. 1. Spring基于xml加载和读取properties文件配置

    在src目录下,新建test.properties配置文件,内容如下 name=root password=123456 logArchiveCron=0/5 * * * * ? 一种是使用sprin ...

  7. linux程序处理po多语言的两种脚本配置方式

    1.在configure.ac里面配置ALL_LINGUAS,然后调用AM_GLIB_GNU_GETTEXT 2.在po目录下面放置LINGUAS文件,由gettextize来生成并处理

  8. spring 事务配置方式以及事务的传播性、隔离级别

    在前面的文章中总结了spring事务的5中配置方式,但是很多方式都不用而且当时的配置使用的所有参数都是默认的参数,这篇文章就看常用的两种事务配置方式并信息配置事务的传播性.隔离级别.以及超时等问题,废 ...

  9. bridged(桥接模式)、NAT(网络地址转换模式)和host-only(主机模式)-VMware下三种网络配置方式

    VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式).要想在网络管理和维护中合理应用它们,你就应该先了解一下这三种工作模式. 1 ...

随机推荐

  1. 难以记住的sql语句

    天,把这篇文章转移到这里,增强一下记忆,找起来也更方便. 导出: mysqldump -u username -p password -h hname dbname tblname > file ...

  2. http验证CertificateValidation

    private void btnopenURL_Click(object sender, EventArgs e) { string strUrl = txtopenURL.Text.Trim(); ...

  3. 4、BufferedIn(out)putStream--->字节输入/输出流的缓冲区类(高效类:高效率读写)

    前言 字节流一次读写一个数组的速度明显比一次读写一个字节的速度快很多,这是加入了数组这样的缓冲区效果,java本身在设计的时候,也考虑到了这样的设计思想(装饰设计模式后面讲解),所以提供了字节缓冲区流 ...

  4. 常用的HTTP状态码如下

    成功的状态码: – 服务器成功返回网页 – 未修改 失败的状态码: – 请求的网页不存在 – 服务器暂时不可用 – 服务器内部错误 下面的不是很常用,记住上面那几个就ok了,有bug了再补充 其他的状 ...

  5. HDU 1008 u Calculate e

    Problem Description A simple mathematical formula for e is where n is allowed to go to infinity. Thi ...

  6. ORACLE 11g dblink 配置升级

    1.如果需要创建全局 DBLink,则需要先确定用户有创建 dblink 的权限: select * from user_sys_privs where privilege like upper('% ...

  7. dubbo 分布式架构学习视频链接

    http://www.roncoo.com/course/view/f614343765bc4aac8597c6d8b38f06fd 书籍 大型分布式网站架构设计与实践 http://item.jd. ...

  8. 老oj1965:polygon半平面交

    题目链接:http://192.168.2.240:8080/JudgeOnline/showproblem?problem_id=1965 polygon半平面交 Time Limit:1000MS ...

  9. MVC3+EF4.1学习系列(三)-----排序 刷选 以及分页

    上篇文章 已经做出了基本的增删改查    但这远远不足以应付实际的项目  今天讲下实际项目中 肯定会有的 排序 刷选  以及分页. 重点想多写点分页的 毕竟这个是任何时候都要有的 而且 我会尽量把这个 ...

  10. MC- 交易并设置止损

    using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; using ATCenterP ...