【问题标题】:Spring error - springframework.web.client.HttpClientErrorException: 404 Not FoundSpring 错误 - springframework.web.client.HttpClientErrorException: 404 Not Found
【发布时间】:2014-09-01 14:01:21
【问题描述】:

我正在尝试使用 Spring 将对象传递给另一个类(我不确定我使用的术语是否正确,我对 Spring很陌生>) 这样:

TestServicesUtils.getTemplate().postForLocation(
     "http://"
     + serverConfig
     + ":"
     + port
     + "/test/rest/TestResultService/insertTestResult/",
    results); 

当我运行程序时,它会到达该行并抛出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)

尝试连接的类:

@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());
    }
}

路径好像没问题,不知道为什么找不到方法。我需要注册路径吗?

【问题讨论】:

  • 您能给我们看看您的 web.xml 文件吗?

标签: java spring maven weblogic


【解决方案1】:

您的路径不正确。如果您有正确的路径但仍然出现错误,那么就是映射错误。 但在这种情况下,您会遇到 404 错误,这意味着该路径不存在。

将路径更改为:@Path("/test/rest/TestResultService/insertTestResult/")

然后,如果您再次遇到错误,则必须注册映射配置的路径。

【讨论】:

  • 我几乎不知道我需要将 ref bean 添加到 application-context.xml
【解决方案2】:

以上答案给了我一个方向!
如果您在从另一个微服务调用一个微服务时遇到此错误,并且您已经为微服务实现了context path 的概念。
考虑在调用时提供上下文路径,作为微服务端点的一部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2017-09-03
    • 2015-01-14
    • 2013-03-10
    • 1970-01-01
    相关资源
    最近更新 更多