我正在尝试使用Spring框架和Apache Tomcat来开发一个RESTful web服务。我添加了两个控制器类,它们有5-6个端点,运行良好。但是自从昨天我尝试添加另一个端点时,我得到了一个奇怪的错误。
@Controller
@RequestMapping("/test")
public class TextController {
@RequestMapping(method=RequestMethod.POST)
public void test() {
System.out.println("Hello world");
}
}当我从浏览器(使用REST客户端)尝试这个URL时,我得到了以下输出:
Hello world
Jun 25, 2014 7:05:55 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ChitChatApp/rest/test/test] in DispatcherServlet with name 'chitchat-dispatcher'url将显示附加的额外"/test“。我的其他API仍然工作得很好。仅仅是我添加的新代码就会给出这个错误。
我的web.xml看起来像这样:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ChitChat Web Service</display-name>
<servlet>
<servlet-name>chitchat-dispatcher</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/chitchat-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>chitchat-dispatcher</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>不知道为什么会突然发生这样的事情。希望在这方面能帮上忙。
发布于 2015-04-27 00:55:19
从@RequestMapping("/test")上看,url应该是"somprefix/test“,但您将请求发送到URL "/ChitChatApp/rest/test/test",这是错误的吗?
https://stackoverflow.com/questions/24420187
复制相似问题