在Spring中采用声明式方法对Hibernate和JDBC进行统一的事务配置(AOP)
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- Hibernate配置事务管理器-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="modify*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.env.persistence.manager.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
<!-- 以下配置的是对JDBC的支持 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@localhost:1521:orcl</value>
</property>
<property name="username">
<value>SRMS</value>
</property>
<property name="password">
<value>SRMS</value>
</property>
<property name="defaultAutoCommit">
<value>false</value>
</property>
</bean>
</beans>
转载于:https://www.cnblogs.com/lowerCaseK/archive/2013/04/23/spring_transaction.html
在Spring中采用声明式方法对Hibernate和JDBC进行统一的事务配置(AOP)相关推荐
- 理解JS中的声明式与命令式
理解JS中的声明式与命令式? 声明式编程 :告诉机器你想要的是什么 让机器想出去做 优缺点 : 声明式减少了可变量(Immutable Variable)的声明,程序更为安全, 代码更加简洁 ...
- spring 中 ApplicationContext 的 refresh 方法做了什么
refresh 方法可以说是Spring中核心的一个方法了,通过这个方法可以获取bean的定义.创建添加bean到spring容器中一个其它扩展功能.记录下相关内容. 有个问题:refresh方法为什 ...
- 8.Spring整合Hibernate_2_声明式的事务管理(Annotation的方式)
声明式的事务管理(AOP的主要用途之一) (Annotation的方式) 1.加入annotation.xsd 2.加入txManager bean 3.<tx:annotation-drive ...
- Spring源码——声明式事务流程
前言 最近回顾了一下Spring源码,准备用思维导图的方式简单的将整个源码内容的流程展示出来,思维导图.图片等文件更新在https://github.com/MrSorrow/spring-frame ...
- spring 注解开启声明式事务
spring开启声明式事务: 导入依赖: pom.xml <dependencies><!-- https://mvnrepository.com/artifact/org.spri ...
- 在 Jenkins 中使用声明式 Pipeline 构建 Android 项目
Blue Ocean 是 Jenkins 推出的一套新的 UI,对比经典 UI 更具有现代化气息.2017 年 4 月 James Dumay 在博客上正式推出了 Blue Ocean 1.0. 兼容 ...
- spring事物管理--声明式(AspectJ)注解实现 (推荐使用)
1.表结构及数据 2.使用的jar包 3.service.Dao层接口与实现类: Dao接口: //转账案例持久层接口 public interface AccountDao {/*** @param ...
- java spring scope_如何在Spring中自定义scope的方法示例
大家对于 Spring 的 scope 应该都不会默认.所谓 scope,字面理解就是"作用域"."范围",如果一个 bean 的 scope 配置为 sing ...
- Spring中策略模式实现方法
一.定义 在策略模式(Strategy Pattern)中,一个类的行为或其算法可以在运行时更改.这种类型的设计模式属于行为型模式.在策略模式中,我们创建表示各种策略的对象和一个行为随着策略对象改变而 ...
最新文章
- SQL Server实用操作小技巧集合
- 日常工作必备之 linux 常用命令分类归纳
- [STL]List的实现
- Qt6.2.1使用clang格式化代码
- 作者:兰艳艳,女,中国科学院计算技术研究所副研究员、硕士生导师。
- 023、JVM实战总结:一步一图:那JVM老年代垃圾回收器CMS工作时,内部又干了些啥?
- 柔性穿刺针有限元模型
- updata pip 报错 TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- 腾讯AI开放平台使用尝试:通过文本翻译API进行汉译英
- 怎么样修改vlan从trunk到access模式,提示renew the default configurations
- nutch2.3 mysql教程_Nutch2.2.1+MySQL+Solr4.10.3安装部署
- Mac OS 打开 NTFS 读写功能
- 谷歌账户跑着跑着没点击了,跑不出去什么原因。
- 菜狗杯Misc打不开的图wp
- 多波次导弹发射中的规划问题(二)
- SpringCloud快速上手
- vue3.0抢先看(附尤雨溪vue分享ppt)
- Swift [UInt8]转16进制字符串
- python将所有excel文档合并
- 如果能天天送书,天天爽就好了,再送5本
热门文章
- 如何卸载office201032位_微软官方安装卸载修复工具、恶意软件删除工具,了解下!...
- 莹石云存储卡不兼容_继入股无锡好达之后,华为再度入股国产滤波器厂商德清华莹...
- java监听mysql_java实时监控mysql数据库变化
- esp32 camera_利用Phyphox和ESP32蓝牙制作欧姆表测电阻
- Java封装(速读版)
- mac tomcat https
- 微信小程序云数据库触底分页加载,下拉无限加载,第一次请求数据随机,随机获取数据库的数据
- iOS自动签名打包(xcodebuild)----常用
- python之XML文件解析
- 近一个月的学习总结(4.8—5.12)