zoukankan      html  css  js  c++  java
  • spring声明式事务

    事务ACID原则:

    1、原子性:确保操作要么成功,要么失败

    2、一致性:资源和状态要么提交成功,要么失败

    3、隔离性:多个业务可能同时操作同一资源,防止数据损坏

    4、持久性:事务一旦提交,无论系统发生什么问题,结果都不会被影响,被持久化写到存储器中。

    spring整合mybatis中的spring-dao.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/aop
           http://www.springframework.org/schema/aop/spring-aop.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx.xsd">
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=GMT%2B8"/>
            <property name="username" value="root"/>
            <property name="password" value="root"/>
        </bean>
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="configLocation" value="classpath:mybatis-config.xml"/>
            <property name="mapperLocations" value="classpath:dao/*.xml"/>
        </bean>
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="*" propagation="REQUIRED"/>
            </tx:attributes>
        </tx:advice>
        <aop:config>
            <aop:pointcut id="txPointCut" expression="execution(* dao.*.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
        </aop:config>
        <aop:aspectj-autoproxy  proxy-target-class="true"/>
    </beans>

    解析:

    以后要使用到事务,则直接拷贝spring-dao.xml内容即可。

  • 相关阅读:
    TP隐藏入口
    CentOs5.2中PHP的升级
    centos 关闭不使用的服务
    也不知怎么了LVS.SH找不到,网上搜了一篇环境搭配CENTOS下面的高可用 参考
    三台CentOS 5 Linux LVS 的DR 模式http负载均衡安装步骤
    分享Centos作为WEB服务器的防火墙规则
    Openssl生成根证书、服务器证书并签核证书
    生成apache证书(https应用)
    openssl生成https证书 (转)
    ls -l 列表信息详解
  • 原文地址:https://www.cnblogs.com/wmskywm/p/13649375.html
Copyright © 2011-2022 走看看