This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Architecture question - Multi-tenancy architecture

I am designing a service with multi-tenancy (i.e. multiple customers co-existing on a single cluster and a single DB).

I am using JPA, and assign a schema per customer (I am on Postgres, which supports this well).

I am new to Spring, and I am trying to figure out the right architecture wrt to dependency injection, specifically EMFs.

One approach I am considering is to use a single application context, and whenever I need an EMF, delegate to an object (my own EMFFactory) that manages all my PUs (one per customer) and not rely on injection for EMFs.

Another idea I had is to have an ApplicationContext per customer, and have a single instance of every bean per customer, including an EMF. I am not clear on how that would work with the injection mechanism: when we set the customer in the servlet or controller (which dictates which app context to use), how does would the right app context get propagated properly?