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

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

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

 1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:aop="http://www.springframework.org/schema/aop"
5 xmlns:context="http://www.springframework.org/schema/context"
6 xmlns:tx="http://www.springframework.org/schema/tx"
7 xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
8 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
9 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
10 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
11
12
13 <!-- 读取db.properties配置信息 -->
14 <context:property-placeholder location="classpath:db.properties"/>
15
16 <!-- 配置一个C3P0数据源 -->
17 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
18 <property name="user" value="${jdbc.user}"/>
19 <property name="password" value="${jdbc.password}"/>
20 <property name="driverClass" value="${jdbc.driverClass}"/>
21 <property name="jdbcUrl" value="${jdbc.jdbcUrl}"/>
22 </bean>
23
24 <!-- 配置一个JdbcTemplate,用来操作数据库 -->
25 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
26 <property name="dataSource" ref="dataSource"/>
27 </bean>
28
29 <!-- 配置dao -->
30 <bean id="bookDao" class="com.proc.dao.BookDao">
31 <property name="jdbcTemplate" ref="jdbcTemplate"/>
32 </bean>
33 <bean id="storeDao" class="com.proc.dao.StoreDao">
34 <property name="jdbcTemplate" ref="jdbcTemplate"/>
35 </bean>
36 <bean id="userDao" class="com.proc.dao.UserDao">
37 <property name="jdbcTemplate" ref="jdbcTemplate"/>
38 </bean>
39
40 <!-- 配置service -->
41 <bean id="bookShopService" class="com.proc.service.BookShopServiceJdbcImps">
42 <property name="bookDao" ref="bookDao"/>
43 <property name="storeDao" ref="storeDao"/>
44 <property name="userDao" ref="userDao"/>
45 </bean>
46
47 <!-- 配置事务管理器 -->
48 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
49 <property name="dataSource" ref="dataSource"></property>
50 </bean>
51
52 <!-- 配置事务属性 -->
53 <tx:advice id="advice">
54 <tx:attributes>
55 <tx:method name="get*" read-only="true"/>
56 <tx:method name="find*" read-only="true"/>
57 <tx:method name="*"/>
58 </tx:attributes>
59 </tx:advice>
60
61 <!-- 配置事务的切入点: AOP切入 -->
62 <aop:config>
63 <!-- 配置切入表达式 -->
64 <aop:pointcut expression="execution(* com.proc.service.*.*(..))" id="pointcut"/>
65 <aop:advisor pointcut-ref="pointcut" advice-ref="advice"></aop:advisor>
66 </aop:config>
67 </beans>

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

代码分析:

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

最新文章

  1. ipa如何通过网络进行安装
  2. Java SCP copy local file to remote implementation
  3. oracle 表被锁定 杀死进程
  4. vpn速度太慢?先从本地网络着手
  5. codeforces 484E
  6. ssh和putty
  7. LeetCode——Jump Game
  8. Spring MVC框架
  9. 使用Pig预测电信用户的移动路径
  10. 使用单例模式实现自己的HttpClient工具类
  11. 我的Python成长之路---第八天---Python基础(24)---2016年3月5日(晴)
  12. 关于springboot启动时候报错:springboot Failed to parse configuration class [Application]
  13. BZOJ 4455: [Zjoi2016]小星星 [容斥原理 树形DP]
  14. [LOJ 6185]烷基计数
  15. JAVA内存分配与回收策略
  16. SQL Server2012数据库开启远程连接
  17. Java线程实现的第三种方式Callable方式与结合Future获取返回值
  18. 动态绑定事件到特定dom元素上,包含新增加的
  19. CentOS 下的邮件通知
  20. notepad++ 如何选择10000行-20000行之间的文本?

热门文章

  1. unittest框架学习笔记五之参数化
  2. Openstack组件部署 — Networking service_安装并配置Controller Node
  3. Decision Tree、Random Forest、AdaBoost、GBDT
  4. msf反弹shell
  5. vue组件通信之非父子组件通信
  6. (转载)前端构建工具gulpjs的使用介绍及技巧
  7. Linux中的网络管理——网络配置及命令
  8. 判断IE版本与各浏览器的语句
  9. linux每日命令(1):gzip命令
  10. Linux 进程间通信 信号(signal)