How to handle multiple subdomains separately in a Spring MVC app?
Su开发者_如何学Cpposing I have two subdomains:
Products:
products.example.com
Users:
users.example.com
How do I set up a single Spring MVC app to handle each of these domains differently (in my case I want to use a different database depending on which subdomain the user arrives from)?
If the same applications is to be used with the multiple subdomains, then you can make an interceptor (implement HandlerInterceptor
) that is invoked for every request and store the subdomain in a ThreadLocal
. Then, based on that value, you can differentiate your actions.
精彩评论