我的使用的是spring annotation异常管理。然后我的service方法中使用了try。。。catch捕捉异常信息,catch块中throw出runtimeException,但是却不会异常回滚,这是为什么?
代码:
@Transactional public Map alterAssessor(AssessorBo assessorBo){ Map map=new HashMap(); try{ OperatorInfoDO operatorInfoDO=new OperatorInfoDO(); OperatorRoleInfoDO operatorRoleInfoDO=new OperatorRoleInfoDO(); AssessorInfoDO assessorInfoDO=new AssessorInfoDO(); String nowTime=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); operatorInfoDO.setOperatorId(assessorBo.getOperatorId()); operatorInfoDO.setUpdateTime(nowTime); operatorInfoDO.setLastUpdateOperator(assessorBo.getCurrentOperator().getOperatorId()); operatorInfoDOMapper.updateByPrimaryKeySelective(operatorInfoDO); operatorRoleInfoDO.setOperatorId(assessorBo.getOperatorId()); operatorRoleInfoDO.setRoleId(assessorBo.getRoleId()); operatorRoleInfoDO.setUpdateTime(nowTime); OperatorRoleInfoDOExample example=new OperatorRoleInfoDOExample(); example.createCriteria().andOperatorIdEqualTo(assessorBo.getOperatorId()); operatorRoleInfoDOMapper.updateByExampleSelective(operatorRoleInfoDO,example); assessorInfoDO.setUsername(assessorBo.getUsername()); assessorInfoDO.setAssName(assessorBo.getAssName()); assessorInfoDO.setOperatorId(assessorBo.getOperatorId()); assessorInfoDO.setFirstAssGroup(assessorBo.getFirstAssGroup()); assessorInfoDO.setIsBlack(assessorBo.getIsBlack()); assessorInfoDO.setIsRefuse(assessorBo.getIsRefuse()); assessorInfoDO.setStatus(assessorBo.getStatus()); assessorInfoDO.setMobile(assessorBo.getMobile()); assessorInfoDOMapper.updateByPrimaryKeySelective(assessorInfoDO); map.put("statusCode","200"); }catch(Exception e){ logger.info("修改审核员信息失败",e); map.put("statusCode","300"); map.put("message","修改审核员失败"); // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); throw new RuntimeException("修改审核员信息失败",e); }finally{ return map; } }
代码逻辑问题,自己调试
是finally影响的,finally中return了map,一定会在方法后执行,也就是抛出异常后还要return这个对象,覆盖掉了前面的结果,所以没有捕捉到异常信息,不回滚!