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?
Asked
Active
Viewed 1.1k times
1 Answers
1
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 a server id
).
Here is more about AbstractRoutingDataSource
: Dynamic DataSource Routing

Bill the Lizard
- 398,270
- 210
- 566
- 880

tolitius
- 22,149
- 6
- 70
- 81
-
2Thanks for the reply, in this example he is using property file for getting the datasource details, In my case i want that to be dynamic,the server details should come up for database. – jaya Sep 22 '11 at 04:37
-
@jaya, can you give a bit more details about what it is you are trying to do, and why a property file approach would not work for you. As usually you know all the databases you work with in advance ( connection details to which you can list in property file[s] ). /litius – tolitius Sep 22 '11 at 20:23
-
2I found this question on a quest of my own to do a similar thing and I can answer the question from my perspective. I need to be able to create data sources on the fly using values found in permanent database. The number of data sources can vary and new ones can be added on the fly. – Andreas Wederbrand Nov 11 '11 at 12:19