如何使用 JDBC 在 Spring 中创建动态连接(数据源)
我有一个 Spring 应用程序,我需要获取 Oracle 表的服务器详细信息,并根据某些服务器 ID 在需要时创建动态连接, 我怎样才能做到这一点?
I have a a spring application where i need to get server details for a oracle table and create dynamic connections as and when require based on some server id,
How can I make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下 Spring 的
AbstractRoutingDataSource
( javadoc-api )。它允许您维护一个“路由器”dataSource
bean,它能够在运行时根据提供的单个属性路由到所需的真实数据源(在您的情况下,它将是一个服务器ID
)。以下是有关
AbstractRoutingDataSource
的更多信息: 动态数据源路由Take a look at Spring's
AbstractRoutingDataSource
( javadoc-api ). Which allows you to maintain a "router"dataSource
bean that would be able to route to a required real dataSource at runtime based on a single property provided ( in your case it would be aserver id
).Here is more about
AbstractRoutingDataSource
: Dynamic DataSource Routing