Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle multiple subdomains separately in a Spring MVC app?

Supposing 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)?

like image 500
CharlieZ Avatar asked Sep 03 '11 13:09

CharlieZ


1 Answers

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.

like image 60
Bozho Avatar answered Oct 18 '22 12:10

Bozho