zoukankan      html  css  js  c++  java
  • SSM 事务

    配置文件

    <!-- 定义事务管理器 -->
    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <!-- 定义事务策略 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <!--所有以query开头的方法都是只读的 -->
    <tx:method name="query*" read-only="true" />
    <tx:method name="get*" read-only="true" />
    <tx:method name="find*" read-only="true" />
    <tx:method name="select*" read-only="true" />
    <!--其他方法使用默认事务策略 -->
    <tx:method name="*" rollback-for="Throwable"/>
    </tx:attributes>
    </tx:advice>

    <aop:config>
    <aop:pointcut id="myPointcut" expression="execution(* cc.openkit..service.*.*(..))" />
    <!--将定义好的事务处理策略应用到上述的切入点 -->
    <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
    </aop:config>


    service层


    @Service
    public class AppConfigService extends BaseService<AppConfig>{

    @Autowired
    private AppConfigMapper appConfigMapper;

    @Transactional(readOnly = false, propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void test() {

    AppConfig appConfig = new AppConfig();
    appConfig.setUpBaseId(AppUtil.uuid());
    AppConfig appConfig1 = new AppConfig();
    appConfig1.setUpBaseId(AppUtil.uuid());
    Integer integer = this.saveSelect(appConfig);
    Integer integer1 =this.saveSelect(appConfig1);
    Integer num=integer + integer1;
    if (num==2){
    System.out.println(1);
    throw new RuntimeException("出现异常了");
    }else{
    }
    }
    }

    抛出异常事物回滚
  • 相关阅读:
    Memcached简介
    TP5 volist
    Getting command line access to PHP and MySQL running MAMP on OSX
    PHP use
    PHP 命名空间(namespace)
    mac 使用 pf 做端口转发
    微信测试帐号如何设置URL和Token,以及相关验证的原理
    ionic开发笔记
    Eclipse下配置Maven
    css引用第三方字体库
  • 原文地址:https://www.cnblogs.com/SeaWxx/p/8124830.html
Copyright © 2011-2022 走看看