Sep 5th, 2012, 08:02 AM
Separate ApplicationContext for each Tenant
Hey! Our company is creating a multi-tenant web application based on spring-mvc. Tenant is determinated by subdomain name. We want to use Hibernate, Hibernate Search, Spring Security and Quartz.
First I tried Hibernate 4 multi-tenancy, but Hibernate Search failed to support it. Then I created a Spring custom "tenant" scope, and had separate session factories for each tenant, but it quickly turned out that while for http requests it works fine, I am not able to determinate tenant for Quartz job as there is no request bound to thread.
When I thought it over I came to conclusion that it would be best to have separate ApplicationContext for each tenant. Most beans are lightweight - just dependencies, so memory footprint should be acceptable. I wouldn't need AOP scoped-proxies for accessing tenant scoped beans. I plan to substitute DispatcherServlet with one capable of routing requests to proper WebApplicationContexts. I will also need to modify springSecurityFilterChain to be aware of above, because each tenant has its own user space.
Now, I am new to Spring and would like to ask if anyone done something like that before and could share experience? Is it right direction at all, how do you think?
Tags for this Thread