Add multiple databases (instead of one) to an existing application-Collection of common programming errors
We are using Mongo Db as a database.
If we got the following JAX-RS service (or some other Stateless/Statefull EJB).
@Path("my_service_path")
@Stateless
public class GetSomeObject{
@Inject
public DB database;
@GET
@Consumes("application/json")
@Produces("application/json")
public SomeDomainObject get(@QueryParam("some_param") String param){
...
database.find(...);
...
return something;
}
}
The PROBLEM: We need to use two or more databases, but in our current source it seems impossible. We are currently using injected DBs, but if we were using EntityManager
implementation or something other we would meet the same problem. Are there some integrated solutions for injecting different instances of a class, depending of user/application. We can try
@Inject
public Map databases;
but we must add too many conditional logic to handle these maps of databases.