如何在Spring Hibernate中的运行时设置数据库名称 [英] How to set database name at runtime in Spring Hibernate

查看:107
本文介绍了如何在Spring Hibernate中的运行时设置数据库名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题描述

我有6个不同机器的6个数据库,并且有一个云服务器。它将在用户登录时决定在应用程序中使用哪个数据库。

我可以连接单个数据库。但我不知道处理数据库的动态名称。

更新:



动态更改数据库,但有一个问题正在进行。只有一个数据库中存在一些常用的存储过程(位于云服务器)(我限制了无法将存储过程添加到所有数据库),所以我无法为任何其他数据库调用存储过程。我怎么打电话?



请给我一些想法。

解决方案

在Spring中有一个名为 AbstractRoutingDataSource 的类,你的需求,通过文档你会发现一些关于如何实现这个的具体类的帮助,你需要改变(或添加)一些现有的代码,以便配置动态的数据源。来自spring source的这个博客正在解释这个问题。 / p>

Problem description

I have 6 databases from 6 different machines, and having one cloud server. It will decided at the time of user login that which database is going to use in application.

I am able to connect with single database. But I have no idea to handle dynamic names of databases.

Update:

I am able to change databases dynamically, but one problem is going on. There are some stored procedures in only one database that is common (placed at cloud server), (I have restriction where I can't add stored procedures to all databases), so I am not able to call stored procedures for any other databases. How can I call?

Please give me some ideas.

解决方案

In Spring there is a class called AbstractRoutingDataSource which will suites for your requirement, Go through the documentation you will find some help on how to implement a concrete class of this, You need to change(or add) some part of you existing code in order to configure the dynamic Data source. This blog from spring source is explaining this in action.

这篇关于如何在Spring Hibernate中的运行时设置数据库名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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