gpt4 book ai didi

spring - 在服务器收到请求后修改 URL

转载 作者:行者123 更新时间:2023-11-28 21:50:19 25 4
gpt4 key购买 nike

我正在尝试使用 Spring 框架和 Apache Tomcat 开发 RESTful Web 服务。我添加了两个 Controller 类,它们有一些 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>

不知道为什么这一切突然开始发生。在此方面将不胜感激。

最佳答案

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

关于spring - 在服务器收到请求后修改 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24420187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com