Servlets 路径规范和多个servlet

Servlets 路径规范和多个servlet,servlets,spring-mvc,jetty,Servlets,Spring Mvc,Jetty,我希望有两个servlet(我正在使用Jetty)提供如下URL: host/aaa/submit host/bbb/submit @Controller public class AaaController { @RequestMapping(value = {"/aaa/submit"}, method = (RequestMethod.POST)) public void handleAaaSubmitPostRequest(final HttpServletRequest

我希望有两个servlet(我正在使用Jetty)提供如下URL:

host/aaa/submit  
host/bbb/submit
@Controller
public class AaaController {
  @RequestMapping(value = {"/aaa/submit"}, method = (RequestMethod.POST))
  public void handleAaaSubmitPostRequest(final HttpServletRequest request,
                                       final HttpServletResponse response,
                                       @RequestBody String body) throws IOException {
}
我已经尝试将servlet的路径规范分别设置为
aaa
bbb
,但是随后我得到了一个异常

two controller methods annotated with @RequestMapping(value = {"/submit"})
(即使这两个方法是在两个不同servlet使用的两个独立控制器类中定义的)。
相反,如果我将两个servlet的路径规范都设置为
/
,并将
@RequestMappings
更改为
aaa/submit
bbb/submit
,我将得到404s。(我想这并不令人惊讶——不确定它应该如何有效地与两个“默认”servlet一起工作)

我应该如何映射这些URL?(先发制人-它们必须是独立的servlet-
aaa
部分应使用或不使用DB,
bbb
部分应在没有DB的情况下失败)

以防万一,这里是码头的背景:

    <property name="servletHandler">
        <bean class="org.mortbay.jetty.servlet.ServletHandler">
            <property name="servlets">
                <list>
                    <bean name="aaaServlet" class="org.mortbay.jetty.servlet.ServletHolder">
                        <property name="name" value="aaa" />
                        <property name="servlet">
                            <bean class="org.springframework.web.servlet.DispatcherServlet" />
                        </property>
                        <property name="initParameters">
                            <map>
                                <entry key="contextConfigLocation" value="classpath:aaa-context.xml" />
                            </map>
                        </property>
                    </bean>
                    <bean name="bbbServlet" class="org.mortbay.jetty.servlet.ServletHolder">
                        <property name="name" value="bbb" />
                        <property name="servlet">
                            <bean class="org.springframework.web.servlet.DispatcherServlet" />
                        </property>
                        <property name="initParameters">
                            <map>
                                <entry key="contextConfigLocation" value="classpath:bbb-context.xml" />
                            </map>
                        </property>
                    </bean>
                </list>
            </property>
            <property name="servletMappings">
                <list>
                    <bean class="org.mortbay.jetty.servlet.ServletMapping">
                        <property name="servletName" value="aaa" />
                        <property name="pathSpec" value="/" />
                    </bean>
                    <bean class="org.mortbay.jetty.servlet.ServletMapping">
                        <property name="servletName" value="bbb" />
                        <property name="pathSpec" value="/" />
                    </bean>
                </list>
            </property>
        </bean>
    </property>


由于控制器似乎处于不同的mvc环境中,因此需要根据以下内容更改控制器:

@Controller
public class AaaController {
  @RequestMapping(value = {/*aaa*/"/submit"}, method = (RequestMethod.POST))
  public void handleAaaSubmitPostRequest(final HttpServletRequest request,
                                       final HttpServletResponse response,
                                       @RequestBody String body) throws IOException {
}


这是因为Spring MVC总是使用不带servlet上下文的路径。

我想您的意思是我还应该将servlet的路径规范设置为
/aaa/*
/bbb/*
。我在我的问题中讨论了这种情况-在启动时,我遇到了这样一个异常:
无法将处理程序“bbbController”映射到URL路径[/submit]:已经有[class AaaController]类型的处理程序被映射。
然后请确保您的控制器只能在不同的mvc上下文中访问,例如,
aaa context.xml中的
aaa控制器
bbb context.xml中的
bbb控制器
。否则,我建议使用带有路径“/”的单一上下文,您最初的
@RequestMapping
解决方案将起作用。顺便说一句,在您当前的配置中,这样的URL是可访问的:
aaa/aaa/submit
aaa/bbb/submit
bbb/bbb/submit
,不是吗?
@Controller
public class AaaController {
  @RequestMapping(value = {/*aaa*/"/submit"}, method = (RequestMethod.POST))
  public void handleAaaSubmitPostRequest(final HttpServletRequest request,
                                       final HttpServletResponse response,
                                       @RequestBody String body) throws IOException {
}
    @Controller
public class BbbController {
  @RequestMapping(value = {/*bbb*/"/submit"}, method = (RequestMethod.POST))
  public void handleBbbSubmitPostRequest(final HttpServletRequest request,
                                       final HttpServletResponse response,
                                       @RequestBody String body) throws IOException {
}