title: dynamically change Spring data source
body: <p>I have a Spring application, i want to change the data source dynamically,ie. when input a DS URL, the Spring beans and all dependency will get updated automatically.I know this is somewhat strange, but anyway i want to achieve that. 
  My Spring configuration as following:</p>
  
  <pre><code>&lt;bean id="majorDataSource" class="org.postgresql.ds.PGSimpleDataSource"&gt;
      &lt;property name="serverName" value="${jdbc.serverName}" /&gt;
      &lt;property name="portNumber" value="${jdbc.portNumber}" /&gt;
      &lt;property name="user" value="${jdbc.username}" /&gt;
      &lt;property name="password" value="${jdbc.password}" /&gt;
      &lt;property name="databaseName" value="${jdbc.databaseName}" /&gt;
  &lt;/bean&gt;
  &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
      &lt;property name="dataSource" ref="majorDataSource"/&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
  &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="majorDataSource"/&gt;
      &lt;property name="configLocation" value="classpath:sqlmap-config.xml"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The questions are:</p>
  
  <ol>
  <li><p>The JDBC URL is stored in properties, which could be changed runtime.</p></li>
  <li><p>Once the URL is changed, i need to re-create the data source and maybe the dependent objects. I could not figure out how to do it elegantly in Spring?</p></li>
  </ol>
  
  <p>I have known that Spring did could dynamically route data source based on one key, but the data source URL is predefined in Spring and will not change runtime. It is not my case.</p>