我是付刚 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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题