基于tx/aop命名空间的spring声明式事务管理
来源:互联网 发布:淘宝开店货源哪里找 编辑:程序博客网 时间:2024/05/18 00:26
我们知道,spring声明式事务管理有两种方式:1、使用tx/aop命名空间XML配置文件式的方式 ;2、使用@Transactional注解的方式。
在本文中,我将会介绍第一种方式配置spring声明式事务管理。
首先,在我们使用spring声明式管理前,我们需要导入几个相关的jar包:
下面我们先编写我们的application.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:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" 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.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd"><bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <!-- transactionManager 顾名思义为 事务管理者 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="mod*" propagation="REQUIRED" /> <tx:method name="*" propagation="REQUIRED" read-only="true" /> </tx:attributes> </tx:advice> <!-- aop配置信息 --> <aop:config> <!-- 这里pointcut为定义aop的切面 --> <aop:pointcut id="interceptorPointCuts" expression="execution(* news.dao.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" /> </aop:config>
注:
1.以上 <tx:attributes> 中<method name=”add*”>里为定义我们在代码中使用 add为开头的方法会启用spring进行事务管理。2.expression=”execution(* news.dao.* .* (..))” 代码当中第一个 * 为定义通配 返回值类型;第二个 * 为定义通配 news.dao包中所有类;第三个* 为定义通配 类中的任意方法。第四(..) 为定义方法中可以有任意参数。
这样,我们在dao层中spring便会实施管理,自动为我们dao层中代码使用事务了。
下一篇,我将为大家介绍基于@Transactional注解方式的spring声明式事务管理。
0 0
- 基于tx/aop命名空间的spring声明式事务管理
- 基于 <tx> 命名空间的声明式事务管理
- Spring基于tx/aop声明式事务配置
- Spring基于tx/aop声明式事务配置
- Spring中基于aop命名空间的AOP 二(声明一个切面、切入点和通知)
- Spring的声明式事务管理<tx:advice/> 有关的设置
- Spring的声明式事务管理<tx:advice/> 有关的设置
- Spring的声明式事务管理<tx:advice/> 有关的设置
- Spring声明式事务(AOP的tx方式)
- 基于Spring AOP实现的声明式事务管理的知识点归纳
- Spring基于声明式的事务管理
- 纯JDBC、Hibernate、Spring的AOP声明式事务管理小结
- Spring事务管理(AOP/声明式式事务管理)
- Spring 2.x AOP声明式配置+声明式事务管理
- Spring声明式事务管理(基于xml的方式)
- Spring声明式事务管理(基于注解的方式)
- 基于@Transactional注解方式的spring声明式事务管理
- spring声明式事务管理(基于TransactionProxyFactoryBean的方式)
- javascript入门基础篇重点 第五节
- android studio 找不到 javax.*包
- java动态代理
- 友盟分享(QQ,空间,微信,朋友圈,微博)遇到的问题
- opencv-2.4.13 vs2013安装配置
- 基于tx/aop命名空间的spring声明式事务管理
- Java集合框架
- 51nod-【1629 B君的圆锥】
- JMX是Java Management Extensions 的简写,即Java管理扩展
- 总结24
- TCP 三次握手四次分手
- slidingmenu简单配置
- Linux进程间通信 -2信号量
- Java MySQL 连接