jonathanzhan 2012-10-28 19:03
浏览 204
已采纳

对于SSI中的action的数据回滚的疑问

最近看了公司的一个框架,很是不明白。框架是用struts,spring,mybatis搭建起来的。简化下就是三层,action,service,dao。事物控制放在了service层。action层只负责页面跳转,以及调用service层。
可是如果一个请求,在service层执行成功后,在action负责跳转的时候产生了一个异常。这个时候数据已经写入到了数据库,我该如何将写入的数据回滚呢?或者我如何修改这个框架的配置。

spring的配置如下:

<?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"
     xmlns:jdbc="http://www.springframework.org/schema/jdbc"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
         <property name="driverClassName"  value="com.mysql.jdbc.Driver" />  
        <property name="username" value="root" />  
        <property name="password" value="123456" />  
        <property name="url"  value="jdbc:mysql://127.0.0.1:3306/ci" />  
    </bean>
    
            <!-- define the SqlSessionFactory -->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="typeAliasesPackage" value="com.leopardsnow.ci.domain" />
    </bean>
    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
      

    <context:component-scan base-package="com.leopardsnow.ci.service" />
    <context:annotation-config />
    <tx:annotation-driven />
    
    <!-- 从base 包中搜索所有下面所有 interface,并将其注册到 Spring Bean容器中,其注册的class bean是MapperFactoryBean。 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.leopardsnow.ci.mapper" />
    </bean>
 
    
</beans>

  • 写回答

8条回答 默认 最新

  • qq415241704 2012-10-29 09:55
    关注

    一般需要做事务处理的异常都是从底层DAO一层层抛上来的,如果事务切面中对相应异常做了检测,就会rollback,按你这种说法,异常是在action中抛出的,除非你对action做切面,检测action抛出的异常,才有可能rollback,但是常规的做法是事务一般处理事务数据处理过程中出现的异常,在action中返回的这种和事务处理无关的异常是不需要回滚的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗