Spring中的事务控制 xml中的配置

2 篇文章 0 订阅
 <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">
        <!--配置业务层-->
        <bean id="accountService" class="com.zsw.sevice.impl.AccountServiceImpl">
        <property name="accountDao" ref="accountDao"></property>
        </bean>
        <bean class="com.zsw.dao.impl.AccountDaoImpl" id="accountDao">
        <property name="dataSource" ref="dataSource"></property>
        </bean>
        <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql:///spring"></property>
        <property name="username" value="root"></property>
        <property name="password" value="123123"></property>
        </bean>
        <!--spring 基于xml的声明式事务控制
        1. 配置事务管理器
        2. 配置事务通知
        3.配置aop中的通用切入点表达式
        4. 建立切入点表达式和事务通知的对应关系
        5. 配置事务的属性  isolation="指定事务的隔离级别"
       
        -->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
        </bean>
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <!--
       propagation="指定事务的传播行为 REQUIRED表示一定会有事务  增删改的选择  查询方法可以选择SUPPORTS"
        read-only ="事务是否只读 只有查询方法才能设置为true只读 默认值 false"
        timeout = "用于指定事务的超时时间" 默认值为 -1  如果指定了数值以秒为单位
        rollback-for="用于指定一个异常 当产生改异常时 事务回滚  产生其他异常时 事务不会滚 没有默认值 任何异常都回滚"
        no-rollback-for=""用于指定一个异常 当产生改异常时 事务不回滚  产生其他异常时 事务会滚 没有默认值 任何异常都回滚"

            -->
        <tx:method name="*" propagation="REQUIRED" read-only="false"/>
        <tx:method name="find*" read-only="true" propagation="SUPPORTS"></tx:method>
        </tx:attributes>
        </tx:advice>
        <aop:config>
        <!--    配置切点表达式-->
        <aop:pointcut id="pt1" expression=" execution(* com.zsw.sevice.impl.*.*(..))"></aop:pointcut>
        <!--配置切入 点表达式和事务通知的对应关系-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pt1">
        </aop:advisor>
        </aop:config>
        </beans>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值