我是付刚 2015-05-27 05:17 采纳率: 100%
浏览 3412
已采纳

spring+mybatis事务不生效,求解

首先是applicationContext.xml文件

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

    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED"/>
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="modify*" propagation="REQUIRED" />
            <tx:method name="edit*" propagation="REQUIRED" />
            <tx:method name="del*" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
            <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="load*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="search*" propagation="SUPPORTS" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="transactionPointcut"
            expression="execution(* com.adon.service..*.*(..))" />
        <aop:advisor pointcut-ref="transactionPointcut"
            advice-ref="transactionAdvice" />
    </aop:config>

接下来是service实现类中的代码

    public JSONObject confirmPassport(String id)  throws Exception{
        PassPortManage pm = new PassPortManage();
        JSONObject json = new JSONObject();
        try {
            pm.setId(new BigDecimal(id));
            //已确认
            pm.setConfirmed(new BigDecimal("1"));
            Integer i = passPortManageMapper.updateByPrimaryKeySelective(pm);
            int q = 5/0;

            if(1==i){
                json.put("success", true);
                json.put("msg", "签收成功!");
            }else{
                json.put("success", false);
                json.put("msg", "签收失败(sql异常)");
            }

        } catch (Exception e) {
            e.printStackTrace();
            json.put("success", false);
            json.put("msg", "签收失败(其他异常)");
            throw new RuntimeException();
        }
        return json;
    }

在int q = 5/0;执行后程序会报错,但记录依旧更改了
求大侠们指教

  • 写回答

5条回答

  • hughjin 博客专家认证 2015-05-28 10:23
    关注
    • com.adon.service.*.*.*(..) 少个星号
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计