I m 试图利用春天工具箱和Eclipse创建的M.VC模板项目增加一个简单的REE服务。 我所要揭露的科技创新服务基本上是一种与任何模式无关的用途。 这些投入是一纸空文,我希望它回过来。 守则部分比较容易,但配置并非易事。 以下是我的相关档案。
I don t really understand why this doesn t work, but when I type in the URL http://localhost:8080/projectName/restfultest/stringreverser/testString I get the error message No mapping found for HTTP request with URI [/projectName/restfultest/stringreverser/] in DispatcherServlet with name restfulServlet
网络:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>restfulServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/restfulServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>restfulServlet</servlet-name>
<url-pattern>/restfultest/*</url-pattern>
</servlet-mapping>
</web-app>
servlet-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet s request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.sample.pkg" />
</beans:beans>
休息服务。
package com.sample.pkg;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value = "/stringreverser")
public class RestfulService {
@RequestMapping(value="/{id}", method=RequestMethod.GET)
public String reverseId(@PathVariable("id") String id) {
String reversed = "";
for (int i = id.length() - 1; i <= 0; --i) {
reversed += id.charAt(i);
}
return reversed;
}
}
事先得到任何帮助!
- 共同