0

次のような URL を提供する 2 つのサーブレット (私は Jetty を使用しています) を使用したいと思います。

host/aaa/submit  
host/bbb/submit

aaaサーブレットのパススペックをそれぞれおよびに設定しようとしましbbbたが、次の行に沿って例外が発生します

two controller methods annotated with @RequestMapping(value = {"/submit"})

(問題の 2 つのメソッドは、2 つの異なるサーブレットで使用される 2 つの別個のコントローラー クラスで定義されていますが)。
代わりに、両方のサーブレットのパス仕様を に設定し/、 と に変更@RequestMappingsするaaa/submitbbb/submit、404 が発生します。(これはそれほど驚くべきことではないと思います - 2 つの「デフォルト」サーブレットで効果的にどのように動作するかはわかりません)

これらの URL をどのようにマッピングすればよいですか? (先制的に - それら別個のサーブレットである必要があります -aaa一部は DB の有無にかかわらず動作する必要があり、bbb一部は DB なしで失敗する必要があります)

念のため、Jetty コンテキストは次のとおりです。

    <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>

そして、次のような 2 つのコントローラー:

@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 {
}
4

1 に答える 1

0

コントローラは異なる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 {
}

    @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 {
}

これは、SpringMVCが常にサーブレットコンテキストのないパスを使用しているために発生します。

于 2013-02-27T11:54:07.277 に答える