zoukankan      html  css  js  c++  java
  • spring 事务配置

    事务配置文档xml

    <!-- from the file 'context.xml' -->
    <?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: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.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd">
    
        <!-- this is the service object that we want to make transactional -->
        <bean id="fooService" class="x.y.service.DefaultFooService"/>
    
        <!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean below) -->
        <tx:advice id="txAdvice" transaction-manager="txManager">
            <!-- the transactional semantics... -->
            <tx:attributes>
                <!-- all methods starting with 'get' are read-only -->
                <tx:method name="get*" read-only="true"/>
                <!-- other methods use the default transaction settings (see below) -->
                <tx:method name="*"/>
            </tx:attributes>
        </tx:advice>
    
        <!-- ensure that the above transactional advice runs for any execution
            of an operation defined by the FooService interface -->
        <aop:config>
            <aop:pointcut id="fooServiceOperation" expression="execution(* x.y.service.FooService.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>
        </aop:config>
    
        <!-- don't forget the DataSource -->
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
            <property name="url" value="jdbc:oracle:thin:@rj-t42:1521:elvis"/>
            <property name="username" value="scott"/>
            <property name="password" value="tiger"/>
        </bean>
    
        <!-- similarly, don't forget the PlatformTransactionManager -->
        <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    
        <!-- other <bean/> definitions here -->
    
    </beans>

    参考资料:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html

  • 相关阅读:
    Binary Tree
    (并查集..含小总结)A
    (超简单并查集)POJ2524 Ubiquitous Religions(8.4.4)
    OpenSees开发(一)windows 上编译opensees (使用vs2005)
    vector的push_back对于拷贝构造和赋值操作的调用
    一个指针的引用引发的血案
    MFC中由左键单击模拟左键双击引起的问题
    CLAPACK动态调用
    SVN部署(远程)客户端篇
    SVN部署(本地)
  • 原文地址:https://www.cnblogs.com/springlight/p/6323522.html
Copyright © 2011-2022 走看看