在服务器收到请求后,将修改URL

时间:2014-06-25 23:23:08

标签: spring spring-mvc tomcat spring-annotations

我正在尝试使用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");
    }
}

当我从浏览器尝试此URL(使用REST客户端)时,我得到以下输出:

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'

该网址正在显示额外的" / 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>

不确定为什么会突然发生这种情况。希望得到一些帮助。

1 个答案:

答案 0 :(得分:0)

@RequestMapping("/test")看来,网址应该是“somprefix / test”,但是您将请求发送到网址“/ ChitChatApp / rest / test / test”,这是错误吗?