Resource.java @RequestMapping(value = "/updateDetails", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("hasRole('" + ROLE_BPM_EAUTH_WF_CLIENT + "')") public ResponseEntity<UpdateStatus> updateDetails(@RequestBody updateRequest updateRequest) throws ServiceException { UpdateStatus response = null; try{ response = controlService.updateDetails(updateRequest); }catch (ControlServiceException controlServiceException) { if(ErrorCodes.ERROR_CODE.FAILED_TO_UPDATE_DETAILS.getCode().equals(controlServiceException.getErrorCode()) || ErrorCodes.ERROR_CODE.FAILED_TO_UPDATE_DETAILS_STALE_DATA_ISSUE.getCode().equals(controlServiceException.getErrorCode())) { final int maxRetryCount = controlService.getMaxRetryCountFromConfig(); response = retryUpdateDetails(updateRequest, 1, maxRetryCount); } else{ throw controlServiceException; } } return new ResponseEntity<>(response, HttpStatus.OK); } Service.java @Override@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { ServiceException.class })public UpdateStatus updateDetails(UpdateRequest updateRequest) throws ServiceException { Object object = updateRequest.getObject(); updateDetailActions(updateRequest); return InformationTransformer.transformStatus(object, true);} private void updateDetailActions(updateRequest updateRequest) throws ServiceException { DefaultDetails defaultDetails = null; if (updateRequest.getEventType().equals(EventTypeEnum.A.getValue())) { updateStatusToA(updateRequest); }
2 回答
动漫人物
TA贡献1815条经验 获得超10个赞
你如何访问你的Service
班级?对于要创建的 Spring 事务,您需要通过 Spring Application Context 访问您的类,然后而不是通过例如创建一个新实例(new Service()
将不起作用),也不会通过变量访问实例或此类(即使变量它的值最初是由 spring 设置的)
慕仙森
TA贡献1827条经验 获得超7个赞
当您在非事务上下文中执行数据库事务时,通常会发生此异常。对于执行数据库事务的方法,您在 spring 中使用 @Transactional 注释。有关事务管理的详细信息,您可以参考 https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/transaction.html
添加回答
举报
0/150
提交
取消