Is there a way to decide what EJB implementation to use at runtime when you have more than one implementation? I can’t use annotations or deployment descriptor because the logic is not known until runtime.
Let’s say that I have the following EJBs implementations:
MyEJBFoo MyEJBBar, both implement MyEJB business interface. How can I still do dependency injection of that EJB if the implementation to use is known until runtime with let’s say a flag called DEV_MODE = TRUE/FALSE stored in a resource bundle and if it is true it must use MyEJBFoo and if it is false then MyEJBBar.
I was thinking factory pattern but I’m not sure if it is the best way to do it.
Use a delegating
MyEJB:Only caveat is that both instances (myEJBFoo and myEJBBar) have to be instantiable no matter what the environment conditions are, because you are injecting both unconditionally in the delegating
MyEJB.