English 中文(简体)
多领域,春天
原标题:Multiple domains with spring mvc

我要说的是,我的申请必须缩短卢爱尔语,但也还有其他事情。 (例如google.comgoo.gl,或facebook.comfb.me

简单地部署两个应用程序是容易的,但(现在)这只是一个简单的应用程序。 利用春天和春天。 我有以下地图:

@RequestMapping(value="/{shortUrlKey}", headers="Host=foo.br")
...
@RequestMapping(value="/{username}")

Alas, the headers annotation act not as given more specific information, but as limit otherwise. 因此,如果我有这两条,则只有后者才被援引,即使我将其开放为。 如果只剩下前者,则为那些来自<条码>foo.br的人工作,如果东道国不同,则不开放。

因此,问题:

  • how can I make two handlers for the same paths, but different URLs / Hosts
  • is it possible to resolve the host dynamically, with a property placeholder configurer (rather than hard-code it in the annotation)

如果存在某种可行的方法解决机制,这两种办法或许都会奏效。 是否有这样的情况?

最佳回答

我的直接建议是写一份服务器过滤器(或一个跳板HandlerInterceptor),从请求中取出东道名称,先到最初要求的道路,然后根据请求转交。

例如,鉴于请求的URL http://goo.gl/my/path,过滤器将转至/goo.gl/my/path。 春天免疫日线的测绘将有一些东西可以进入牙齿。 ant式野生卡片的合成物(例如>>**/my/path>)或可变体(例如{requestHost}/my/path>)可能会有帮助。

另一种做法是,过滤器可设置一个定制头盔或要求包含所要求东道方的特性,但这种特性可能不太灵活。

不过,我不肯定你在问题第二部分的含义。

这里是一座工作月:

@Override
public boolean preHandle(HttpServletRequest request,
        HttpServletResponse response, Object handler) throws Exception {

    if (request.getRequestURL().toString().contains(shortenerDomain)
            && !request.getRequestURI().startsWith(SHORT_URI_PREFIX)) {

        request.getRequestDispatcher(SHORT_URI_PREFIX + request.getRequestURI())
                .forward(request, response);
        return false;
    } else {
        return true;
    }
}
问题回答

Based on your description, it sounds like you could have two controller methods with each domain header mapping:

@RequestMapping(value="/{shortUrlKey}", headers="Host=foo.br")
public void fooBr() { ... }

@RequestMapping(value="/{shortUrlKey}", headers="Host=bar.bz")
public void barBz() { ... }




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签