Spring整合hibernate:3、使用XML进行声明式的事务管理
2024-09-21 06:39:45
配置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里又指定了一个数据源。
最新文章
- libusb-win32简介~
- sql拷贝表结构不拷贝表数据
- DOM节点-appendChild
- MVVM模式应用 之的RelayCommand的使用
- Linux Shell编程(5)——shell特殊字符(下)
- react-native 自己搭建热更新服务器
- SSL/TLS原理详解
- CLR的组成和运转
- CSS3 02. 边框、边框圆角、边框阴影、边框图片、渐变、线性渐变、径向渐变、背景、过渡transition、2D转换
- api大全
- oracle 创建表空间TABLESPACE
- android Gui系统之SurfaceFlinger(1)---SurfaceFlinger概论【转】
- Shell中read命令--学习
- spring cloud 之 Feign 使用HTTP请求远程服务
- gcc升级
- gpart 分区工具
- 1089 Intervals(中文版)
- Java学习笔记01
- [摸鱼]cdq分治 &;&; 学习笔记
- COGS2216 你猜是不是KMP
热门文章
- python的socket网络编程(二)
- 如何在Kubernetes集群动态使用 NAS 持久卷
- Laravel核心解读--异常处理
- [转载]Javassist 使用指南(一)
- PHP 根据IP地址获取所在城市
- sql 筛选表中指定字段包含26某个小写字母
- grafana二次开发
- Delphi编码转换
- TCP_DB_中间件_遗留问题
- ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbilisi, November 24, 2010