使用spring + hibernate连接到在运行时检索的数据库 [英] connect to database retrieved at runtime using spring + hibernate
问题描述
我在我的项目中使用spring +休眠事务管理器.最初,我要连接到主数据库并检索公司中的几个项目,例如,如果每个项目有200个项目将与之相关联的数据库,我想连接到与用户在运行时选择的项目相关联的数据库. /p>
在运行时是否有理想的方式连接数据库?
有一个Spring抽象
帖子有一个不错的版本,而更新的教程,您可以在其中了解更多详细信息. I am using spring + hibernate transaction manager in the my project. Initially I am connecting to main database and retrieving several projects in a company, say if there are 200 projects each project will have database associated with it, I want to connect to database associated with the project that is selected by user at run time. Is there any ideal way to connect to database at run time? There's a Spring abstraction AbstractRoutingDataSource that has been around for a long time, and that fits your bill The general idea is that a routing DataSource acts as an intermediary
- while the ‘real’ DataSource can be determined dynamically at runtime based upon a lookup key. There is a good post and a newer tutorial, where you can learn more details. 这篇关于使用spring + hibernate连接到在运行时检索的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!