java - Changing Spring bean properties on fly -


i've got following problem. there 2 datasources 2 dbs: current(a) , stand by(b). if doesn't respond, try connect b.

this how acheave that.

  • interceptor checks if connection bad
  • interceptor swap datasource url, if goes wrong

datasources spring beans. change spring bean properties on fly. ok? @ code:

@autowired @qualifier("datasourcemain") private oracle.jdbc.pool.oracledatasource dsmain;  @autowired @qualifier("datasourcestandby") private oracle.jdbc.pool.oracledatasource dsstandby;  public void swapurl() {     try {         string dsmainurl = dsmain.geturl();         dsmain.seturl(dsstandby.geturl());         dsstandby.seturl(dsmainurl);     } catch (exception e) {         e.printstacktrace();     } } 

as can see, code works, don't know if it's approach or not.

can check if solves problem? seems similiar question

dynamically change spring data source

which seems done in more elegant way


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -