简体   繁体   中英

spring-mvc and subdomains

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.localhost doesn't point anywhere.

You need to add it to the hosts file pointing to 127.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM