首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring @Transactional注释行为

Spring @Transactional注释行为
EN

Stack Overflow用户
提问于 2016-07-11 15:51:51
回答 0查看 400关注 0票数 0

我正在构建一个工作流系统,其中的一个服务层- WorkflowServiceImpl,处理文档并向用户发送通知。还有另一个服务方法,它有一个方法post() DocumentServiceImpl,它在内部调用WorkflowServiceImpl.process()方法。

代码语言:javascript
复制
@Service 
public class WorkflowServiceImpl implements WorkflowService{

    @Transactional(propagation=Propagation.REQUIRES_NEW, noRollbackFor=WorkflowException.class)
    public void process(WorkflowDocument document) throws WorkflowException {

        Boolean result = process(document);
        if(!result){
            throw new WorkflowException();
        }
    }

    private Boolean process(WorkflowDocument document){
        //some processing on document
        updateDocument();
        sendNotifications();
    }

    private void updateDocument(WorkflowDocument document){
        //some update operation
    }

    private void sendNotifications(WorkflowDocument document){
        //send notifications - insertion operation
    }
}

@Service 
public class DocumentServiceImpl implements DocumentService{

    @Autowired private WorkflowService workflowService;

    @Transactional
    public void post(){

        //some operations

        workflowService.process(document);

        //some other operations
    }
}

如你所见,我已经标记了

代码语言:javascript
复制
DocumentServiceImpl.post() as @Transactional  
WorkflowServiceImpl.process() as @Transactional(propagation=Propagation.REQUIRES_NEW, noRollbackFor=WorkflowException.class)

我正在努力实现这一点:

代码语言:javascript
复制
1. WorkflowServiceImpl.process() method should commit always(update document and send notifications) - whether a WorkflowException is thrown or not
2. DocumentServiceImpl.post() method should rollback, when WorkflowException is thrown 

当我尝试使用上面的事务配置时

代码语言:javascript
复制
1. When WorkflowException is not thrown, the code worked as expected - committed both WorkflowServiceImpl.process() and DocumentServiceImpl.post() methods
2. When WorkflowException is thrown, the request processing is not completed (I can see the request processing symbol in the browser) 

我找不到代码出了什么问题。我使用的是spring版本3.1.4

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38301747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档