6

現在、REST サービス専用に Spring MVC を適用している Web アプリがあります。残りのサービスを の下に表示したいのですが${contextPath}/rest/**、これを設定すると次のようになります。

「Spring MVC Dispatcher Servlet」という名前の DispatcherServlet で、URI [/myapp/rest/testSvc/message] を持つ HTTP 要求のマッピングが見つかりませんでした

web.xmlは持っています:

<servlet>
  <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      /WEB-INF/spring/servlet-context.xml
    </param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
  <url-pattern>/rest</url-pattern>
</servlet-mapping>

servlet-context.xml、これは問題なく、起動時に登録されるサービスを登録しています。

<context:component-scan base-package="com.mycompany.myapp.rest" />
<mvc:annotation-driven />

私のコントローラーは次のようになります。

@Controller
@RequestMapping(value = "/rest/testService")
public class TestREST {
    @RequestMapping(value="message", method=RequestMethod.GET)
    public @ResponseBody String getMessage() {
        return "REST working";
    }

* .resturl-patternweb.xml変更すると、リクエスト マッピングが機能messagemessage.restます。

4

2 に答える 2

25

問題は、との両方で/restプレフィックスを繰り返している可能性があります。どちらか一方にある必要がありますが、両方にあるべきではありません。web.xml@RequestMapping

<url-pattern>/rest</url-pattern>

@RequestMapping(value = "/testService")

動作するパス@RequestMappingは、サーブレット部分に続くパスの部分でありweb.xml、サーブレット部分をとして定義している/pathため、@RequestMapping残っているもの、つまり、と一致し/testServiceます。

現在の形式では、あなた@RequestMappingは実際にと一致して{contextPath}/rest/rest/testServiceいます。

于 2011-03-20T10:49:01.147 に答える
7

おそらく、<url-pattern>/rest/*</url-pattern> または<url-pattern>/rest*</url-pattern> に変更してみて、それが役立つかどうかを確認してください。

于 2011-03-20T07:55:08.470 に答える