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 ...
随机推荐
- Java Hashtable详细介绍和使用示例
①对Hashtable有个整体认识 和HashMap一样,Hashtable 也是一个散列表,它存储的内容是键值对(key-value)映射.Hashtable 继承于Dictionary,实现了Ma ...
- java内存空间
Java内存分配与管理是Java的核心技术之一,之前我们曾介绍过Java的内存管理与内存泄露以及Java垃圾回收方面的知识,今天我们再次深入Java核心,详细介绍一下Java在内存分配方面的知识.一般 ...
- AJAX跨域问题解决方法(4)——调用方解决跨域
调用方解决跨域的方法只有一种,那就是隐藏跨域. 何为隐藏跨域? 隐藏跨域的核心思路是通过反向代理隐藏跨域以欺骗浏览器 什么是反向代理?反向代理是指通过中间服务器使得访问同一个域名的两个不同url最终会 ...
- Greatest Common Increasing Subsequence
/*HDU1423 最长公共递增*/ #include <stdio.h> #include <string.h> #include <iostream> usin ...
- CentOS 6.3编译安装LAMP环境笔记
转载地址:http://www.jb51.net/article/54969.htm 最近抽空在虚拟机上测试成功了LAMP各个最新版本的整合编译安装,算是把之前的博文整合精简,以下内容均在CENTOS ...
- Python面试题之解读Socketserver & Tcpserver
在解析socketserver是如工作之前,我们先看看socektserver类的继承关系图: 请求类继承关系: server类继承关系: 有了上面的继承关系图后,我们解析socketserver就轻 ...
- CSS Margin(外边距)
CSS Margin(外边距) 一.简介 CSS margin(外边距)属性定义元素周围的空间. margin 清除周围的(外边框)元素区域.margin 没有背景颜色,是完全透明的. margin ...
- Vue中使用百度地图——根据输入框输入的内容,获取详细地址
知识点:在Vue.js项目中调用百度地图API,实现input框,输入地址,在百度地图上定位到准确地址,获得到经纬度 参考博客: 百度地图的引用,初步了解参考博客:http://blog.csdn. ...
- Dll Hijacker
#coding=utf-8 # # Dll Hijacker # # platform: Python 2.x @ Windows # # author:Coca1ne import os,sys,t ...
- 关于http请求ContentType:application/x-www-form-urlencoded
在又一次http请求过程中,模拟post请求提交form表单数据一直提示部分参数为空,后面检查发现是缺少ContentType:application/x-www-form-urlencoded的原因 ...