gpt4 book ai didi

java - 为什么我测试的时候显示404? org.springframework.web.client.HttpClientErrorException : 404 null

转载 作者:行者123 更新时间:2023-12-01 16:19:13 25 4
gpt4 key购买 nike

2020年6月12日更新我已经解决了这个问题。问题的原因是我的jetty服务器没有正常启动。我把jdk从14改成了1.7。所有可以吸取的教训是:

<url-pattern>/</url-pattern>

它始终可以接收所有网络请求。

感谢您回答我的问题,祝您生活顺利。

我在SpringMVC系统下写了一个控制方法和一个测试方法。我还配置了一个本地的tomcat,是不是需要在tomcat中配置正确的url呢?tomcat中的url地址为:

http://localhost:8080/chapter17
    @Test
public void testhandle41() {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.add("userName", "tom");
form.add("password", "123456");
form.add("age", "45");
restTemplate.postForLocation(
"http://localhost:8080/chapter17/user/handle41.html", form);
}
    @RequestMapping(value = "/handle41")
public String handle41(@RequestBody String body) {
System.out.println(body);
return "success";
}

错误是

org.springframework.web.client.HttpClientErrorException: 404 null

at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:357)
at com.smart.web.UserControllerTest.testhandle41(UserControllerTest.java:37)

看起来不像地址解析问题。我尝试了以下两种配置。

<url-pattern>/</url-pattern>

<url-pattern>*.html</url-pattern>

在这两种情况下,我都测试了使用或不使用.html。不好。

最佳答案

您确定您展示的方法正确吗?

at com.smart.web.UserControllerTest.testhandle42(UserControllerTest.java:37)

它说错误发生在 testhandle42 中,而您已显示 testhandle41。

关于java - 为什么我测试的时候显示404? org.springframework.web.client.HttpClientErrorException : 404 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62316324/

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