繁体   English   中英

在春季声明式事务管理中,提交事务时

[英]In spring declarative transaction management when transaction commited

如所描述的,春季声明式交易管理中实际执行的交易。 例如,假设我有以下代码

@Service
@Transactional
class CustomerAService{
    public void processCustomer(Customer customer){
        //call dao and insert customer
        furtherProcessCustomer(Customer customer);
        //last line (a)
    }

    @Transactional(propagation=Propagation.REQUIRES_NEW)
    public void furtherProcessCustomer(Customer customer){
        //call another dao do some db work

        //last line (b)
    }
}

假设如果我停止执行@行//最后一行(a),那么会为processCustomer()方法提交事务。 我试图在网上搜索,但没有得到太多信息

春天的事务管理是通过面向方面的编程(AOP)代理对象进行的。 这意味着该方法必须干净地返回以便提交事务。 下图中的代码是“目标方法”,而事务是在“事务顾问”中提交的。 此处有更多文档。

AOP交易处理

您的示例有点微妙,因为在同一类内部调用了furtherProcessCustomer方法,该方法不会通过AOP代理对象进行调用,因此不会使用@Transactional(propagation=Propagation.REQUIRES_NEW)

如果您还有另一个服务(也带有@Transactional批注),然后又调用了furtherProcessCustomer ,则这将通过AOP代理对象发生,因此将具有嵌套事务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM