参考前面的声明式事务的例子: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切入点。指定需要为哪些类和方法采用事务

最新文章

  1. Ubuntu 14.04 使用的一些笔记
  2. 作用域闭包、预解释和this关键字综合题目
  3. WebAPI GET和POST请求的几种方式
  4. XSS学习笔记(一个)-点击劫持
  5. SQL Server 增删改
  6. Java面试题之最扯淡的String
  7. SQLServer 发布订阅(Replication)造成的Memroy压力(cmemthread等待)
  8. Mysql得隔离级别
  9. yml多环境配置
  10. MySQL在高内存、IO利用率上的几个优化点
  11. spring mvc 参数绑定
  12. ElasticSearch安装部署(Windows)
  13. [ASP.NET]初试Web API
  14. Oracle事务与锁
  15. .Net Core全球化多语言
  16. OpenGL(1)-环境搭建
  17. 51nod 1571 最近等对 | 线段树 离线
  18. 131. 分割回文串 javascript实现
  19. ThinkPHP3.2.3 PHPExcel读取excel插入数据库
  20. MyEclipse中出现Address already in use:JVM_Bind:8080

热门文章

  1. 【BZOJ】4709: [Jsoi2011]柠檬
  2. 11.m进制转十进制
  3. 53.FIB词链
  4. wampserver -- 取消PHP页面Warning和Notice级别的报错
  5. [转][译][Android基础]Android Fragment之间的通信
  6. Codeforces Round #300 B. Quasi Binary 水题
  7. mybatis源码分析(7)-----缓存Cache(一级缓存,二级缓存)
  8. eclipse.ini 文件使用说明
  9. Spring Bean init-method 和 destroy-method实例
  10. Git 报错:git - error: RPC failed; curl 18 transfer closed with outstanding read data remaining 解决方案