Thursday, 18 March 2010

Switching between datasources during runtime

Many a times we might want to unit test daos across multiple instances of the same database.


Many a times we might want to update multiple instance of a same database schema , so in such cases we would implement all dao methos in one dao however want to execute the method across multiple databases. In such cases we would want to switch the datasource the dao is connected to during runtime.

AbstractRoutingDataSource is the answer I have found for my problem.


One blog worth mentioning here is http://blog.springsource.com/2007/01/23/dynamic-datasource-routing/ which helped me understand the whole concept and implement the same.