私は春のサービスが初めてで、String Hello World を返す単純な Web サービスの例を作成しようとしています。私のコード構成は次のとおりです。
<servlet>
<servlet-name>myServletName</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.MyPackageDirectionWebServices.remoting</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyServletName</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</servlet-mapping>
HelloWs.java
package com.MyPackageDirectionWebServices.remoting;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/hello")
public class HelloWs {
@RequestMapping(value= "helloWorld", method = RequestMethod.GET)
@ResponseBody
public String HelloWorld() {
return "Hello World";
}
そして、私の AppContext-Remoting.xml にフォローアノテーションを追加しました。
<mvc:annotation-driven />
<context:component-scan base-package="com.MyPackageDirectionServices.remoting" />
しかし、アプリを起動してサービスに行くと:
localhost:8080/MyAppname/rest/hello/helloWorld
HTTP 404- を取得し、Eclipse コンソールで次のエラーを見つけました。
WARN : org.springframework.web.servlet.PageNotFound - 名前が 'MyServletName の DispatcherServlet で、URI [/MyAppname/rest/hello/helloWorld] の HTTP リクエストのマッピングが見つかりません
誰かがこれを手伝ってくれますか?たくさんありがとう!