配置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"?>
    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里又指定了一个数据源。

最新文章

  1. libusb-win32简介~
  2. sql拷贝表结构不拷贝表数据
  3. DOM节点-appendChild
  4. MVVM模式应用 之的RelayCommand的使用
  5. Linux Shell编程(5)——shell特殊字符(下)
  6. react-native 自己搭建热更新服务器
  7. SSL/TLS原理详解
  8. CLR的组成和运转
  9. CSS3 02. 边框、边框圆角、边框阴影、边框图片、渐变、线性渐变、径向渐变、背景、过渡transition、2D转换
  10. api大全
  11. oracle 创建表空间TABLESPACE
  12. android Gui系统之SurfaceFlinger(1)---SurfaceFlinger概论【转】
  13. Shell中read命令--学习
  14. spring cloud 之 Feign 使用HTTP请求远程服务
  15. gcc升级
  16. gpart 分区工具
  17. 1089 Intervals(中文版)
  18. Java学习笔记01
  19. [摸鱼]cdq分治 &amp;&amp; 学习笔记
  20. COGS2216 你猜是不是KMP

热门文章

  1. python的socket网络编程(二)
  2. 如何在Kubernetes集群动态使用 NAS 持久卷
  3. Laravel核心解读--异常处理
  4. [转载]Javassist 使用指南(一)
  5. PHP 根据IP地址获取所在城市
  6. sql 筛选表中指定字段包含26某个小写字母
  7. grafana二次开发
  8. Delphi编码转换
  9. TCP_DB_中间件_遗留问题
  10. ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbilisi, November 24, 2010