2013年9月16日星期一

spring set up multiple data sources, but the data source configuration data are written in a configuration repository how

System according to certain rules to switch to a different data source. . . Business needs data source ( address ah Username Password what ) are configured in a library ( a fixed database ) to facilitate maintenance , how to achieve ah online spring configuration of multi-database implementations is written dead in a spring configuration file
Jiqiu ! ! !
------ Solution - -------------------------------------------
fact that the white how to dynamically according to the configuration information repository to generate an XML file Bale.

you configure multiple data sources defined XML file name , such as call db.xml.

longer provide a properties file , used to write the configuration database JDBC information is used to create the configuration database connection. But you can not rely on this Spring , you need to write your own Class.forname () method to load the JDBC driver .

The final step is to read information using JDOM or any other tool to generate Spring XML configuration file , start Spring.
------ Solution ---------------------------------------- ----
configure two datasource
------ For reference only --------------------------- ------------
2 F, this method good trouble ah. . . Is there any way to run a program when you load the new data source . .
------ For reference only -------------------------------------- -
Well this last I found a solution , or use the DynamicDataSource inherited AbstractRoutingDataSource achieve determineCurrentLookupKey () method . . However, this method is carried out in the data source to judge may refer http://www.oschina.net/question/239572_118084 thinking about this wrong , but even though he 's fine with me . . .
------ For reference only -------------------------------------- -
you want to be in multiple data sources to switch ? Or read from the configuration database other database connection information. . . . Do not second do you ask ?

没有评论:

发表评论