3

I am programming service for getting data from database and providing them via REST service. It uses spring mvc. My database connection cofiguration is in property file from where it is loaded by spring as a data source bean during context initialization.

Now my problem is - I want to change configuration in properties file (for example change database info) but I can't afford to restart the application server so the new configuration does not load.

How can I re-initialize spring context or some particular beans so the newly defined properties are used?

Wolf
  • 871
  • 1
  • 7
  • 21

1 Answers1

1

If you want multiple data source in spring and need to deciding appropriate data source dynamically at runtime you can do this with AbstractRoutingDataSource provided with spring. You have to implement your lookup key logic for determining data-source in method determineCurrentLookupKey(). With this you can map different beans to different data-sources at runtime. following are few questions relating to this context.

How to programatically change databases in Spring with one DataSource?

Also

dynamically change Spring data source

Community
  • 1
  • 1
Yogesh
  • 4,546
  • 2
  • 32
  • 41
  • thank you for the answer, but how about when i know only one data source and other one (or more) would be specified at runtime by rewriting properties in my jdbc-properties file? Maybe I can do this using information from links you provided, but I can not see how. – Wolf Feb 18 '14 at 09:38
  • You can create a certain public static variable which is returned by `determineCurrentLookupKey` at runtime, according that returned value your data-source bean will be selected. check this example http://howtodoinjava.com/2013/12/28/spring-3-2-5-abstractroutingdatasource-example/ – Yogesh Feb 18 '14 at 09:55