Many guys maybe encountered this situation in actually working.he want to gain the spring bean object through the dynamic injection. such as there are two datasources one is normal database, another is archive database for backup the normal database. so in your application ,you want to access the normal database in your special time based the implementation. and maybe some function need you to access the archive database based on the same code . spring
here is the one of the solution for this issue.app
you can configure two datasource in your spring configuration file,one is normal db,another is the archive db.this
in your own object which is defined by yourself for gaining the datasource. you only need to handler the datasource through gain the spring context ,here I mean BeanFactory. code
how to gain the beanfactory in your own class. orm
the biggest way is implement the BeanFactoryAware interface. and set the current beanfactory.ci