Spring整合hibernate:3、使用XML进行声明式的事务管理
配置applicationContext.xml文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<? xml version = "1.0" encoding = "UTF-8" ?> xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:context = "http://www.springframework.org/schema/context" xmlns:aop = "http://www.springframework.org/schema/aop" xmlns:tx = "http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans < context:annotation-config /> < context:component-scan base-package = "com.fz.annotation" /> < bean class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > < property name = "locations" value = "classpath:jdbc.properties" /> </ bean > < bean id = "dataSource" destroy-method = "close" class = "org.apache.commons.dbcp.BasicDataSource" > < property name = "driverClassName" value = "${jdbc.driverClassName}" /> < property name = "url" value = "${jdbc.url}" /> < property name = "username" value = "${jdbc.username}" /> < property name = "password" value = "${jdbc.password}" /> </ bean > < bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" > < property name = "dataSource" ref = "dataSource" /> < property name = "packagesToScan" > < list > < value >com.fz.annotation.model</ value > </ list > </ property > < property name = "hibernateProperties" > < props > < prop key = "hibernate.dialect" >org.hibernate.dialect.MySQLDialect</ prop > < prop key = "hibernate.show_sql" >true</ prop > < prop key = "hibernate.format_sql" >true</ prop > </ props > </ property > </ bean > <!-- 使用xml方式管理事务 --> < bean id = "txManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager" > < property name = "sessionFactory" ref = "sessionFactory" /> </ bean > < aop:config > < aop:pointcut expression = "execution(public * com.fz.annotation.service..*.*(..))" id = "bussinessService" /> < aop:advisor advice-ref = "txAdvice" pointcut-ref = "bussinessService" /> </ aop:config > < tx:advice id = "txAdvice" transaction-manager = "txManager" > < tx:attributes > <!-- 所有以find开头的方法,readOnly=true --> < tx:method name = "find*" read-only = "true" /> < tx:method name = "add*" propagation = "REQUIRED" /> < tx:method name = "insert*" propagation = "REQUIRED" /> < tx:method name = "update*" propagation = "REQUIRED" /> < tx:method name = "del*" propagation = "REQUIRED" /> < tx:method name = "delete*" propagation = "REQUIRED" /> </ tx:attributes > </ tx:advice > </ beans > |
1.定义一个aop:pointcut的切入点,也就是需要处理事务的具体service
2.定义一个具体该怎么做的指导aop:advisor,需要指导的pointcut就是刚才定义的pointcut。指导的建议可以自定义一个建议txAdvice
3.txAvice需要使用到数据库,所以需要一个Spring具体管理的事务对象txManager。
4.Spring管理事务又需要SessionFactory,所以又配置一个SessionFactory的属性。而SessionFactory里又指定了一个数据源。
Spring整合hibernate:3、使用XML进行声明式的事务管理的更多相关文章
- 9.Spring整合Hibernate_2_声明式的事务管理(Xml的方式)
使用xml的方式进行声明式的事务管理 推荐使用xml的方式,因为可以同时为多个方法进行声明 <!-- 开启Spring中的事务管理(声明式的事务管理) xml--> <!-- 不管是 ...
- Spring整合Hibernate 二 - 声明式的事务管理
Spring大战Hibernate之声明式的事务管理 Spring配置文件: 添加事务管理类的bean: <bean id="txManager" class="o ...
- 8.Spring整合Hibernate_2_声明式的事务管理(Annotation的方式)
声明式的事务管理(AOP的主要用途之一) (Annotation的方式) 1.加入annotation.xsd 2.加入txManager bean 3.<tx:annotation-drive ...
- spring整合mybatis,ioc容器及声明式事务配置
步骤: 1.创建jdbc.properties文件,用来管理存放连接数据库的相关信息 jdbc.properties:jdbc.user=root jdbc.password=123456 jdbc. ...
- Spring整合Hibernate:2、使用Annotation方式进行声明式的事务管理
1.加入DataSourceTransactionManager的命名空间 修改applicationContext.xml文件,增加如下内容: 1 2 3 4 5 6 7 8 9 10 11 12 ...
- Rabbitmq与spring整合之重要组件介绍——AMQP声明式配置&RabbitTemplate组件
上一节是使用rabbitAdmin的管理组件进行声明队列,交换器,绑定等操作,本节则是采用AMQP声明式配置来声明这些东西.AMQP声明主要是通过@Bean注解进行的. 配置: package com ...
- spring声明式的事务管理
spring支持声明式事务管理和编程式事务管理两种方式. 编程式事务使用TransactionTemplate来定义,可在代码级别对事务进行定义. 声明式事务基于aop来实现,缺点是其最细粒度的事务声 ...
- Spring整合Hibernate的XML文件配置,以及web.xml文件配置
利用Spring整合Hibernate时的XML文件配置 applicationContext.xml <?xml version="1.0" encoding=" ...
- Spring整合Hibernate的步骤
为什么要整合Hibernate?1.使用Spring的IOC功能管理SessionFactory对象 LocalSessionFactoryBean2.使用Spring管理Session对象 Hib ...
随机推荐
- hdfs启动后进入safe mode,Problem connecting to server
原创文章:http://blog.csdn.net/renfengjun/article/details/25320043 DN中日志如下: 2017-06-17 06:35:59,242 WARN ...
- Safari中的input、textarea无法输入的问题
原因是这两种表单元素上应用了user-select:none的css属性.一般没人刻意这么做,可能是这样的情况: * { user-select: none; } 在css中排除掉这两种元素就好了: ...
- 【Linux学习】1.Linux基础知识
记录学习Linux 系统的相关知识点,欢迎大家拍砖交流,一起成长:QQ:2712192471 作者背景:前端开发工程师 | Python | web安全爱好者 一,Windows系统下 Linux 的 ...
- tomcat源码调试
三.tomcat目录结构 tomcat的下载安装有很多教程,不再赘述. 现在的tomcat已经到9了,当tomcat下载安装完成后,其目录大致如下: 除了上面的文件夹,还有四个文件: ...
- Openwrt架设GIT服务
#下载宝刷LEDE版系统后, 在上面安装git包 opkg update opkg install git #安装好后在将git仓库装到SD(TF)卡上 #用fdisk对SD 卡分区 #fdisk / ...
- 20145303刘俊谦 Java 代码托管
(20145303刘俊谦) Java 第三周代码托管 这是最近保存下来的代码,今天一起上传的,有很多在代码学习过程中无意识删掉了:
- 2017杭电ACM集训队单人排位赛 - 6
2017杭电ACM集训队单人排位赛 - 6 排名 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 59 1 X X 1 1 X X 0 1 ...
- 百度console输出
try{ if(window.console&&window.console.log) { console.log("一张网页,要经历怎样的过程,才能抵达用户面前?\n一位新 ...
- http://www.kindsoft.net/docs/qna.html
http://www.kindsoft.net/docs/qna.html 感觉 Kindediter 非常好用 界面效果好 API也全面 很不错的编辑器
- git介绍及常用命令
Git简介 linus 用C语言编写 2005年诞生 分布式版本管理系统 速度快,适合大规模,跨地区多人协同开发 分布式管理 Git 生态 Git 分布式版本管理系统 Gitlab git私库解决方案 ...