参考前面的声明式事务的例子:http://www.cnblogs.com/caoyc/p/5632198.html

我们做了相应的修改。在dao中和service中的各个类中,去掉所有注解标签。然后为为每个字段提供一个setXxx()方法

最后就是配置applicationContext.xml文件了。内容如下:

 <?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!-- 读取db.properties配置信息 -->
<context:property-placeholder location="classpath:db.properties"/> <!-- 配置一个C3P0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"/>
</bean> <!-- 配置一个JdbcTemplate,用来操作数据库 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean> <!-- 配置dao -->
<bean id="bookDao" class="com.proc.dao.BookDao">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean>
<bean id="storeDao" class="com.proc.dao.StoreDao">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean>
<bean id="userDao" class="com.proc.dao.UserDao">
<property name="jdbcTemplate" ref="jdbcTemplate"/>
</bean> <!-- 配置service -->
<bean id="bookShopService" class="com.proc.service.BookShopServiceJdbcImps">
<property name="bookDao" ref="bookDao"/>
<property name="storeDao" ref="storeDao"/>
<property name="userDao" ref="userDao"/>
</bean> <!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> <!-- 配置事务属性 -->
<tx:advice id="advice">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice> <!-- 配置事务的切入点: AOP切入 -->
<aop:config>
<!-- 配置切入表达式 -->
<aop:pointcut expression="execution(* com.proc.service.*.*(..))" id="pointcut"/>
<aop:advisor pointcut-ref="pointcut" advice-ref="advice"></aop:advisor>
</aop:config>
</beans>

  这样基于xml方式的事务就配置好了。

代码分析:

  事务采用的是AOP的方式。所以需要配置AOP切入点。指定需要为哪些类和方法采用事务

Spring 基于xml配置方式的事务的更多相关文章

  1. Spring 基于xml配置方式的事务(14)

    参考前面的声明式事务的例子:http://www.cnblogs.com/caoyc/p/5632198.html 我们做了相应的修改.在dao中和service中的各个类中,去掉所有注解标签.然后为 ...

  2. Spring 基于xml配置方式的AOP

    我们具体用代码来说明: 1.ArithmeticCalculator.java package com.proc; public interface ArithmeticCalculator { in ...

  3. Spring 基于xml配置方式的AOP(8)

    1.ArithmeticCalculator.java 1 package com.proc; 2 3 public interface ArithmeticCalculator { 4 int ad ...

  4. spring基于xml的声明式事务控制配置步骤

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  5. Spring3.2 中 Bean 定义之基于 XML 配置方式的源码解析

    Spring3.2 中 Bean 定义之基于 XML 配置方式的源码解析 本文简要介绍了基于 Spring 的 web project 的启动流程,详细分析了 Spring 框架将开发人员基于 XML ...

  6. struts_20_对Action中所有方法、某一个方法进行输入校验(基于XML配置方式实现输入校验)

    第01步:导包 第02步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app ...

  7. struts2视频学习笔记 22-23(基于XML配置方式实现对action的所有方法及部分方法进行校验)

    课时22 基于XML配置方式实现对action的所有方法进行校验   使用基于XML配置方式实现输入校验时,Action也需要继承ActionSupport,并且提供校验文件,校验文件和action类 ...

  8. 转载 - Struts2基于XML配置方式实现对action的所有方法进行输入校验

    出处:http://www.cnblogs.com/Laupaul/archive/2012/03/15/2398360.html http://www.blogjava.net/focusJ/arc ...

  9. ssm整合(基于xml配置方式)

    本文是基于xml配置的方式来整合SpringMVC.Spring和Mybatis(基于注解的方式会再写一篇文章),步骤如下: (1)首先自然是依赖包的配置文件 pom.xml <project ...

随机推荐

  1. bzoj 2434 ac自动机

    ac自动机中,如果以trie中的节点为节点,(fail[i],i)为边,可以建立一颗树,该树有如下特点:“节点u是节点v的祖先 当且仅当 u代表的字符串是v代表的字符串的一个后缀”.(u代表的字符串是 ...

  2. Codeforces Round #346 (Div. 2) E. New Reform dfs

    E. New Reform 题目连接: http://www.codeforces.com/contest/659/problem/E Description Berland has n cities ...

  3. PAT甲级1034. Head of a Gang

    PAT甲级1034. Head of a Gang 题意: 警方找到一个帮派的头的一种方式是检查人民的电话.如果A和B之间有电话,我们说A和B是相关的.关系的权重被定义为两人之间所有电话的总时间长度. ...

  4. 2016.3 idea 注册码

    idea 最新官方版本:2016.3 idea 注册码 1.下载最新idea 下载地址:https://www.jetbrains.com/idea/ 2.安装 Windows 直接下载 .exe 文 ...

  5. iptables学习与研究(使用LOG记录失败日志)

    原文地址: http://blog.csdn.net/fafa211/article/details/2307581 通常情况下,iptables的默认政策为DROP,不匹配的数据包将被直接丢弃.但在 ...

  6. 使用 pm2-web 监控 pm2 服务运行状态

    pm2-web 是一款 pm2 服务状态监控程序,基于 web . 安装 $ npm install -g pm2-web 运行(默认是在8080端口) $ pm2-web 配置 pm2-web 将会 ...

  7. web小流量实验方案

    近期在思考怎么做小流量,在网上搜了一下,总结例如以下: 1.前提,站点pv已经达到了一定的规模,比方上百万pv,不做小流量冒然更新功能,可能会带来大面积流量损失.在这样的前提下须要做小流量实验 2.什 ...

  8. Sql server left join,right join和inner join的比较

    转载于:http://www.2cto.com/database/201206/137067.html   Sql server left join,right join和inner join的比较 ...

  9. 怎么删除桌面右键"打开好桌道壁纸"

    “好桌道”是一款优秀的桌面美化工具,其中的子程序“好桌道壁纸”是其重要的组成部分,但是在卸载其子程序“好桌道壁纸”时,往往会在桌面的鼠标右键中残留下“打开好桌道壁纸”项,下面解密通过修改注册表的方式彻 ...

  10. C#转义字符[转]

    C#转义字符: 一种特殊的字符常量 以反斜线"\"开头,后跟一个或几个字符 具有特定的含义,不同于字符原有的意义,故称“转义”字符. 主要用来表示那些用一般字符不便于表示的控制代码 ...