使用Spring的XML声明式事务管理
来源:互联网 发布:淘宝鹊桥活动怎样 编辑:程序博客网 时间:2024/05/19 19:58
1、设置applicationContext.xml中的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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
2、加载依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
3、声明一个事务管理器
applicationContext.xml:
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sf2"></property>
</bean>
4、配置事务管理策略
<tx:advice transaction-manager="txManager" id="advices">
<tx:attributes >
<tx:method name="get*" read-only="true" propagation="SUPPORTS" isolation="DEFAULT"/>
<tx:method name="Save*" propagation="REQUIRED" isolation="DEFAULT"/>
</tx:attributes>
</tx:advice>
5、配置AOP
<aop:config>
<aop:pointcut expression="execution(* cn.com.bochy.dao.*.*(..))" id="poincut"/>
<aop:advisor advice-ref="advices" pointcut-ref="poincut"/>
</aop:config>
6、session从当前线程中拿
session=sf.getCurrentSession();
不可以使用Opensession()
7、 设置current_session_context_class(高版本的Spring可不配)
在hibernate.cfg.xml中,设置
<property name="current_session_context_class">
org.springframework.orm.hibernate4.SpringSessionContext
</property>
阅读全文
0 0
- 使用Spring的XML声明式事务管理
- spring使用xml进行声明式事务管理
- Spring的使用Annotation以及XML进行声明式事务管理
- Spring使用XML进行声明式的事务管理
- Spring的使用Annotation以及XML进行声明式事务管理
- Spring声明式事务管理之xml事务管理
- 【spring框架】spring使用XML进行声明式事务管理
- Spring事务管理——使用XML配置声明式事务
- Spring事务管理——使用XML配置声明式事务
- Spring事务管理——使用XML配置声明式事务
- Spring事务管理——使用XML配置声明式事务
- Spring声明式事务管理(基于xml的方式)
- spring声明式事务管理(基于AspectJ的xml方式)
- Spring声明式事务管理、事务的传播行为xml配置
- Spring 声明式事务管理----基于AspectJ的XML方式
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- Spring整合hibernate:3、使用XML进行声明式的事务管理
- 同一服务器下配置多域名,去掉Tomcat端口号,Nginx反向代理做转发
- Android中如何隐藏掉顶部通知栏
- list和set集合的几种遍历方式
- 二、JSX的介绍
- Objective-c新特性
- 使用Spring的XML声明式事务管理
- hibernate中的JPA
- Android Studio 打包只有app-release-unaligned.apk没有app-release.apk
- 三、渲染元素
- Android如何使用XML创建一个环形渐变颜色图片
- <NOIP> 15 . P1428 小鱼比可爱
- ActionBar标题居中
- java.lang.OutOfMemoryError: Java heap space解决方法
- angularjs数据请求、分页问题