Web.xml中
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>SpringRest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringRest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
春季背景
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd" >
<mvc:annotation-driven/>
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.mypackage"/>
</beans>
控制器
@RestController
@RequestMapping("/springPolicyService")
public class SpringRestController {
@Autowired(required=true)
PolicyService policyService;
@RequestMapping(name="/policies/{id}", method=RequestMethod.GET, headers="Accept=application/json")
public List getPolicies(@PathVariable("id") int id){
List<Policy> list= policyService.getPolicies(id);
return list;
}
}
但是,只要我提供此网址: 的 http://localhost:8080/SpringRest/springPolicyService/policies/1
我明白了: Jun 26,2017 3:57:53 am org.springframework.web.servlet.PageNotFound noHandlerFound 警告:在名为“SpringRest”的DispatcherServlet中找不到具有URI [/ SpringRest / springPolicyService / policies / 1]的HTTP请求的映射