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>
  • 相关阅读:
    EF4 中Selftrack entity 错误用于单web开发中要注意的地方
    C#验证文件类型
    简单实际的方式分隔Admin 区域
    SQLite 资源汇总
    C# Enum 类型的本地化
    Associations in EF Code First CTP5: Part 1 – Complex Types
    asp.net网站管理工具 的 地址(Web Site Administration Tool )
    wordpress 文章缩略图功能
    Sql Server 2008 Fulltext search Error: Word breaking timed out for the fulltext query string.
    用javascript创建第一个windows8 metro应用
  • 原文地址:https://www.cnblogs.com/haoyy/p/5229943.html
Copyright © 2011-2022 走看看