I am using spring mvc+hibernate+two databases
So for example:
I create 2 sessionFactories. sessionFactory1
(using datasource1
) and sessionFactory2
(using datasource2
).
Would it be possible to change sessionFactory1
or sessionFactory2
to sessionFactory at runtime so that the dao/s references them. sessionFactory is already autowired to all dao/s.
I am searching for it right now I think @Configuration can help me but I am not sure.
I am trying AbstractRoutingDataSource but don't think it helps.
Usually Spring wires your beans on application startup, so "re-wiring" (replacing references to sessionFactory1 with references to sessionFactory2 on runtime) does not seem easy to implement.
Maybe you could implement a "proxy bean" that is wired to your DAO objects and change the "target SessionFactory" of your proxy bean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With