当url模式是路径时,无法让Spring MVC调度程序正常工作
我有一个Web应用程序,我们目前正在为REST服务应用spring MVC。 我们希望我们的rest服务显示在${contextPath}/rest/**
,但是当我设置它时,我们得到:
在DispatcherServlet中找不到具有URI [/ myapp / rest / testSvc / message]的HTTP请求的映射,其名称为“Spring MVC Dispatcher Servlet”
我的web.xml
有:
Spring MVC Dispatcher Servlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/servlet-context.xml 1 Spring MVC Dispatcher Servlet /rest
servlet-context.xml
,这很好,并且在启动时注册服务。
我的控制器如下所示:
@Controller @RequestMapping(value = "/rest/testService") public class TestREST { @RequestMapping(value="message", method=RequestMethod.GET) public @ResponseBody String getMessage() { return "REST working"; }
如果我将web.xml
的url-pattern
更改为* .rest,并将我的请求映射message
给message.rest
则可以正常工作。
问题可能是您在web.xml
和@RequestMapping
重复了/rest
前缀。 它应该在一个或两个中,但不是两个,例如
/rest
和
@RequestMapping(value = "/testService")
@RequestMapping
操作的路径是servlet部分之后的路径的一部分,并且web.xml
将servlet部分定义为/path
,因此@RequestMapping
与剩下的任何内容匹配,即/testService
。
在其当前forms中,您的@RequestMapping
实际上与{contextPath}/rest/rest/testService
匹配。
也许您可以尝试更改为
>或
>,看看是否有帮助。