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

    <!-- 声明式事务处理 -->
        <!-- 1:配置事务管理器(切面) -->
        <bean id="trManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
        </bean>
       
        <!-- 
            2:配置通知,让通知放置到切面中
                * tx:method name="":表示对切入点方法的细化:注意,增删改的方法需要使用事务控制,查询的方法不需要事务的控制
                        saveAccount:表示切入点方法中方法名为saveAccount的方法,(1)强
                        save*:表示切入点方法中以save开头的方法                (2)中强
                        *:表示切入点所有的方法                            (3)小强
                * isolation="DEFAULT":事务的隔离级别
                        DEFAULT    使用后端数据库默认的隔离级别(spring中的的选择项)
                * propagation="REQUIRED":事务的传播行为
                        REQUIRED    业务方法需要在一个事务中运行。如果方法运行时,已经处在一个事务中,那么加入到该事务,否则为自己创建一个新的事务
                * read-only="false":控制事务是可写数据库,还是只读
                                * 增删改操作需要可写
                                * 查询只需要只读
                                
                * 注意:何 RuntimeException 将触发事务回滚,但是任何 checked Exception 将不触发事务回滚
                
         -->
         <tx:advice id="trAdvice" transaction-manager="trManager">
         
         </tx:advice>
       <!--  <tx:advice id="trAdvice" transaction-manager="trManager">
            <tx:attributes>
                <tx:method name="save*" isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>
                <tx:method name="update*" isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>
                <tx:method name="delete*" isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>
                <tx:method name="*" read-only="true"/>
            </tx:attributes>
        </tx:advice> -->
        <!-- 
            3:aop切面编程思想,将通知关联切入点,即事务控制Service层
                * aop:pointcut:定义切入点,表示Service从中间的方法
                * expression="execution(* com.itheima.service..*.*(..))":
                        表示返回类型任意,com.itheima.service..*表示com.itheima.service包及其子包中所有类,类中的所有方法
                        .*(..)表示类中的所有方法,参数任意
        -->
        <aop:config>
        <aop:pointcut expression="execution(* com.itheima.service..*.*(..))" id="trPointcut"/>
        <aop:advisor advice-ref="trAdvice"  pointcut-ref="trPointcut"/>
        </aop:config>
  • 相关阅读:
    简单的生成编号的存储过程
    表实体上面添加特性获取到连接字符串
    Spring 静态注入讲解(MethodInvokingFactoryBean)
    嵌套的SQL另外一种写法
    微信小程序之列表下拉加载更多
    微信小程序之--->轮播图制作
    javascript变量作用域
    struts2升级报ActionContextCleanUp<<is deprecated。Please use the new filters
    java日期加减
    数字转大写
  • 原文地址:https://www.cnblogs.com/baijin05/p/5056981.html
Copyright © 2011-2022 走看看