I’m currently developing an application with spring-mvc and I would like to work with subdomains. Supose that the user john is registered in my app.
So, when the user types john.myapp.com/something. I want to stored john in someplace (don’t know where) and redirect to the controller that listen “something”. I Hope to be clear.
I wrote this interceptor:
public class SubdomainHandlerInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
System.out.println(request.getServletPath());
return super.preHandle(request, response, handler);
}
}
In my spring-servlet.xml
<mvc:interceptors>
<bean class="ar.com.saturn.core.interceptor.SubdomainHandlerInterceptor"> </bean>
</mvc:interceptors>
The problem is that when I wrote “john.localhost:8080/Saturn” nothings happens the SubdomainHandlerInterceptor is not reached.
Do i have to write something else instead of a HandlerInterceptorAdapter to work with subdomains, or am I missing something?.
I hope to be clear. Thanks in advance.
Judging from the symptoms the domain
john.localhostdoesn’t point anywhere.You need to add it to the
hostsfile pointing to127.0.0.1(or ipv6 equivalent).In case of real, hosted domains you need to add an entry to your dns configuration pointing to the destination server. Most virtualhosts take care of that for you.