Java Spring 错误 - springframework.web.client.HttpClientErrorException: 404 Not Found
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25607518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring error - springframework.web.client.HttpClientErrorException: 404 Not Found
提问by david
I'm trying to pass an object to another class using Spring(I'm not sure I'm using the right terms, I'm very new to Spring) this way:
我正在尝试使用Spring将对象传递给另一个类(我不确定我使用的是正确的术语,我对Spring非常陌生)以这种方式:
TestServicesUtils.getTemplate().postForLocation(
"http://"
+ serverConfig
+ ":"
+ port
+ "/test/rest/TestResultService/insertTestResult/",
results);
When I ran the program it gets to that line and it trows an Exception
:
当我运行该程序时,它会到达该行并显示Exception
:
log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.HttpClient).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.springframework.web.client.HttpClientErrorException: 404 Not Found
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76)
The class that's trying to connect to:
试图连接到的类:
@Service("TestRestImpl")
@Path("TestResultService")
@Produces("application/json")
public class TesttRestImpl implements TestResultRest
{
...
@POST
@Override
@Path("/insertTestResult")
@Consumes("application/xml")
public void insertTestResult(TestRestCollection list) {
testresultservicedao.insertTestResult(list.getListOfResults());
}
}
The path seems to be fine, I don't know why it can't find the method. Do I need to register the path?
路径好像没问题,不知道为什么找不到方法。我需要注册路径吗?
采纳答案by hurricane
Your path is not correct. If you have a correct path and still get an error then is a mapping error. But in this situation you have 404 error which means that path doesn't exist.
你的路径不对。如果您有正确的路径但仍然出现错误,则是映射错误。但是在这种情况下,您会遇到 404 错误,这意味着该路径不存在。
Change your path to : @Path("/test/rest/TestResultService/insertTestResult/")
将您的路径更改为: @Path("/test/rest/TestResultService/insertTestResult/")
Then if you have an error again you have to register your path to mapping conf.
然后,如果再次出现错误,则必须注册映射 conf 的路径。