步骤:

1.添加aop、tx命名空间声明;

2.配置事务管理器;

3.配置增强;

4.配置aop

具体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:p="http://www.springframework.org/schema/p"
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.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
"> <bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="system"></property>
<property name="password" value="ok"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/it/entity/Stu.hbm.xml</value></list>
</property>
</bean>
<!-- spring声明式事务 3个步骤-->
<!-- 1 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 2 增强 -->
<tx:advice id="tx" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="batch*"/>
</tx:attributes>
</tx:advice>
<!-- 3 aop -->
<aop:config>
<aop:pointcut expression="execution(* com.it.biz.impl.*.*(..))" id="pt"/>
<aop:advisor advice-ref="tx" pointcut-ref="pt"/>
</aop:config>
<!-- spring声明式事务写在最上面 --> <!-- stuDao -->
<bean id="studao" class="com.it.dao.impl.StuDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- stuBiz -->
<bean id="stubiz" class="com.it.biz.impl.StuBizImpl">
<property name="studao" ref="studao"/>
</bean>
<!-- stuAction -->
<bean id="stuaction" class="com.it.action.StuAction">
<property name="stubiz" ref="stubiz"/>
</bean> </beans>

spring给予XML配置的声明式事务的更多相关文章

  1. spring事物配置,声明式事务管理和基于@Transactional注解的使用

    http://blog.csdn.net/bao19901210/article/details/41724355 http://www.cnblogs.com/leiOOlei/p/3725911. ...

  2. spring事务配置,声明式事务管理和基于@Transactional注解的使用(转载)

    原文地址:http://blog.csdn.net/bao19901210/article/details/41724355 事务管理对于企业应用来说是至关重要的,好使出现异常情况,它也可以保证数据的 ...

  3. 使用spring声明式事务,spring使用AOP来支持声明式事务,会根据事务属性,自动在方法调用之前决定是否开启一个事务,并在方法执行之后决定事务提交或回滚事务。

    使用spring声明式事务,spring使用AOP来支持声明式事务,会根据事务属性,自动在方法调用之前决定是否开启一个事务,并在方法执行之后决定事务提交或回滚事务.

  4. Spring:(三) --常见数据源及声明式事务配置

    Spring自带了一组数据访问框架,集成了多种数据访问技术.无论我们是直接通过 JDBC 还是像Hibernate或Mybatis那样的框架实现数据持久化,Spring都可以为我们消除持久化代码中那些 ...

  5. Spring -12 -声明式事务及完整的XML配置文件信息 -声明式事务中的相关属性(tx:advice的标签)

    1.编程式事务: 1.1由程序员编程事务控制代码. 1.2OpenSessionInView 就属于编程式事务: session.commit()和rollback() 2.声明式事务: 2.1事务控 ...

  6. spring 事物(三)—— 声明式事务管理详解

    spring的事务处理分为两种: 1.编程式事务:在程序中控制事务开始,执行和提交:详情请点此跳转: 2.声明式事务:在Spring配置文件中对事务进行配置,无须在程序中写代码:(建议使用) 我对&q ...

  7. Spring学习之Spring中AOP方式切入声明式事务

    mybatis-spring官方文档说明 一个使用 MyBatis-Spring 的其中一个主要原因是它允许 MyBatis 参与到 Spring 的事务管理中.而不是给 MyBatis 创建一个新的 ...

  8. Spring AOP应用之一:声明式事务

    所有数据访问技术都提供事务处理机制,这些技术提供了API用来开启事务.提交事务完成数据操作,或者在发生错误的时候回滚数据.Spring本身并不支持事务实现,同时只是负责提供标准接口来处理不同数据访问技 ...

  9. Spring注解驱动开发之声明式事务

    前言:现今SpringBoot.SpringCloud技术非常火热,作为Spring之上的框架,他们大量使用到了Spring的一些底层注解.原理,比如@Conditional.@Import.@Ena ...

随机推荐

  1. java基础-泛型的优点

    1.性能 对值类型使用非泛型集合类,在把值类型转换为引用类型,和把引用类型转换为值类型时,需要进行装箱和拆箱操作.装箱和拆箱的操作很容易实现,但是性能损失较大.假如使用泛型,就可以避免装箱和拆箱操作. ...

  2. PAT Advanced 1085 Perfect Sequence (25) [⼆分,two pointers]

    题目 Given a sequence of positive integers and another positive integer p. The sequence is said to be ...

  3. JQuery 点击子控件事件,不会触发父控件的事件

     $('.order-delete').on('tap', function (e) {                  console.log('删除1');                  c ...

  4. Java web:html+css(2020.1.5)

    html 1.font-size中1em=16px 2.html中font不要使用 3.链接标签<a></a>禁止下划线样式设置 <style> a{ color: ...

  5. python all()函数

    1.描述all() 函数——用于判断给定的可迭代参数 iterable 中的所有元素是否都为TRUE,如果是返回 True,否则返回 False.元素除了是 0.空.FALSE 外都算 TRUE.2. ...

  6. MySQL--存储引擎的特性

    常用存储引擎的对比 特点 MyISAM InnoDB MEMORY MERGE NDB 存储限制 有 64TB 有 没有 有 事务安全   支持       锁机制 表锁 行锁 表锁 表锁 行锁 B树 ...

  7. 创建Maven项目时Maven中的GroupID和ArtifactID的意思

    GroupID 是项目组织中唯一的标识符,对应Java包结构,在项目中看到的是main目录里java的目录结构. ArtifactID是项目的唯一的标识符,实际对应项目的名称(就是idea中工程的名字 ...

  8. 四十、LAMP与LNMP加速与缓存优化进阶实战上部

    实例: 一. 所有服务器配置定时时间同步,必须通过web server上网. 有两种方式: 1.服务器A能进行上网,作为web server ,通过指定为ntp服务器,所有服务器访问这个服务器 2.服 ...

  9. sbt 设置

    修改 sbtopts for shell # zkk -sbt-dir D:/DATA/.sbt -sbt-boot D:/DATA/.sbt/boot -ivy D:/DATA/.ivy2 修改 s ...

  10. [徐州网络赛]Longest subsequence

    [徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...