dispatcher 서블릿을 web.xml의/*에 매핑하지 않으면 내 컨트롤러가 호출되지 않는 이상한 시나리오가 있습니다. 마지막으로이 web.xml에 매핑되는Spring MVC @RequestMapping not working
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<context:component-scan base-package="com.test.rest.controller" />
:
@Controller
public class UserController {
@RequestMapping(value = "/rest/users", method = RequestMethod.GET)
public ModelAndView getUsers(HttpServletRequest request) throws RestException {
...
}
}
그리고 애플리케이션 컨텍스트 :
<servlet>
<servlet-name>rest-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/restContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
이 예상 작품으로, 즉 I 나는 RequestMapping와 컨트롤러를 정의/rest/users에게 요청할 수 있습니다. 나는에 web.xml에 매핑을 변경할 경우 :
<servlet-mapping>
<servlet-name>rest-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
나는 MVC 오류가 :
WARN servlet.PageNotFound: No mapping found for HTTP request with URI [/rest/users] in DispatcherServlet with name 'rest-servlet'.
오류가 요청 디스패처 - 서블릿에 매핑되고 있음을 나타 내기 때문에 정말 이상한 것 같다 , 아직 변경된 유일한 것은 서블릿 매핑입니다.
누구에게도이 문제가 발생 했습니까?
감사합니다 안톤 유일한 - 당신이
로 변경할 경우 귀하의 요청이
rest/rest/users
일반적인 패턴과 같이해야한다 내가 직면하는 문제는 MVC 디스패처 서블릿 (GWT 등)과 함께 정의 된 다른 서블릿이 있으므로 모든 것을 경로 지정하고 싶지 않다는 점입니다. 약간의 URL 재 작성 옵션을 살펴볼 필요가 있습니다. –
서블릿 선언에을 정의 할 수 있습니다. 귀하의 시나리오에서 Spring MVC를/rest와 컨트롤러에/users에 매핑 할 수 있습니다. –
Anton
가져 왔습니다. 이제 도움이되었습니다. 감사합니다. –