zoukankan      html  css  js  c++  java
  • Spring声明式事务配置——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: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 
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-2.5.xsd
               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
        <context:annotation-config />
        <context:component-scan base-package="com.bluesky" />
    
        <!-- 第一步:配置sessionFactory或者dataSource,这里是配置的sessionFactory-->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="configLocation" value="classpath:hibernate.cfg.xml" />
            <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
        </bean>
    
        <!-- 第二步:定义事务管理器(声明式的事务) -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
    
    <!-- 第三步:配置事务方法传播特性 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="save*" propagation="REQUIRED" />
                <tx:method name="add*" propagation="REQUIRED" />
                <tx:method name="del*" propagation="REQUIRED" />
                <tx:method name="update*" propagation="REQUIRED" />
                <tx:method name="batch*" propagation="REQUIRED" />
                <tx:method name="complete*" propagation="REQUIRED" />
                <tx:method name="*" read-only="false" />
            </tx:attributes>
        </tx:advice>
    
    <!-- 第四步:配置事务aop切面 -->
        <aop:config>
            <aop:pointcut id="interceptorPointCuts" expression="execution(* com.bluesky.spring.dao.*.*(..))" />
            <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" />
        </aop:config>
    </bean>
  • 相关阅读:
    [RxSwift教程]14、其他操作符:delay、materialize、timeout等
    [RxSwift教程]13、连接操作符:connect、publish、replay、multicast
    Java虚拟机类加载机制及双亲委派模式分析
    面试系列-如何设计一个类
    谈谈 MySQL 的 JSON 数据类型
    Java 多线程编程(2-异步中包含同步)
    还堵在高速路上吗?带你进入Scratch世界带你飞
    SQL Server SSIS相关介绍
    SQL Server开启READ_COMMITTED_SNAPSHOT
    SqlServer中select语句引起的死锁
  • 原文地址:https://www.cnblogs.com/wqinggo/p/6742362.html
Copyright © 2011-2022 走看看