参考前面的声明式事务的例子: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. 对Java Serializable(序列化)的理解和总结(二)

    遇到这个 Java Serializable 序列化这个接口,我们可能会有如下的问题a,什么叫序列化和反序列化 b,作用.为啥要实现这个 Serializable 接口,也就是为啥要序列化 c,ser ...

  2. Map按照数值进行排序

    public static Map<String, Integer> sortMapByValue(Map<String, Integer> oriMap) { if (ori ...

  3. HDU 3974 Assign the task 并查集/图论/线段树

    Assign the task Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  4. linux基础命令学习(四)用户与群组

    一.linux用户账号的管理 linux用户账号的管理主要包括用户添加.用户删除.用户修改. 添加用户账号就是在系统创建一个新账号,然后为新账号分为用户号.用户组.主目录和登录Shell等资源. 刚添 ...

  5. 我的jlink破解失败经历

    http://fallenwind.spaces.eepw.com.cn/articles/article/item/59116 标题:我的jlink破解失败经历2009-07-12 01:16:56 ...

  6. 无线遥控检测仪 A890-RES

    本产品为无线遥控接收器发射器的生产调试项目开发而设计,能自动识别接收并显示遥控器的所有信息:频率.芯片类型.周期.地址码.数据码,并能自动计算振荡阻值,35组自动保存.315M.433M 双频同时待机 ...

  7. [置顶] linux常用命令大全

    SSH 密令控制台 user/pwd 一:停止tomcat 1,cd .. 进入根目录 2,cd home/ 3,ll 4,cd bin/ 进入tomcat bin目录 5,ll 6,ps -ef | ...

  8. The differentiation program with abstract data

    #!r6rs ( import ( rnrs base ( 6 ) )          ( rnrs io simple ( 6 ) ) ) ( define ( deriv exp var )   ...

  9. 三款工作流引擎比较:WWF、netBPM 和 ccflow

    下面将对目前比较主流的三款工作流进行介绍和比较,然后通过三款流程引擎分别设计一个较典型的流程来给大家分别演示这三款创建流程的过程.这三款工作流程引擎分别是 Windows Workflow Found ...

  10. /etc/fstab格式的问题

    [root@localhost etc]# cat fstab /dev/VolGroup00/LogVol00 /                       ext3    defaults    ...