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 .
here is the one of the solution for this issue.
you can configure two datasource in your spring configuration file,one is normal db,another is the archive db.
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.
how to gain the beanfactory in your own class.
the biggest way is implement the BeanFactoryAware interface. and set the current beanfactory.