提交事务后Spring是否关闭连接? [英] Does Spring close connection after committing transaction?

查看:70
本文介绍了提交事务后Spring是否关闭连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在一篇教程中读到 Spring 在事务提交后关闭连接.

I've recently read in one tutorial that Spring closes connection after transaction commit.

这是真的吗?我在 Spring 参考文档中找不到任何相关信息.

Is that true? I can't find anything about it in the Spring reference documentation.

背后的原理是什么?从现在开始,我认为连接和事务之间存在一对多的关系.

What's the rationale behind it? Since now, I thought that there is a one-to-many relation between connection and transactions.

推荐答案

Spring 会在事务完成时调用 close(),这可能来自提交或回滚.close() 是否真正关闭真正的 JDBC 连接取决于 DataSource 配置.如果它是一个普通的 JDBC 连接,那么它实际上会关闭.如果它是一个连接池,那么它可能会在关闭时返回到池中.

Spring calls close() when the transaction finishes which could be from either a commit or rollback. Whether or not close() actually closes a real JDBC connection depends on the DataSource configuration. If it's a plain JDBC connection, then it will actually close. If it is a connection pool then it will probably just be returned to the pool on close.

这篇关于提交事务后Spring是否关闭连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆