2014-09-01 153 views
0

我想通過一個對象到另一個類使用春天(我不知道我使用正確的術語,我很新)這樣說:春天錯誤 - springframework.web.client.HttpClientErrorException:404沒有找到

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

當我運行它得到該行的程序,它trows的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()); 
    } 
} 

路徑似乎很好,我不知道爲什麼找不到方法。我需要註冊路徑嗎?

+0

你能告訴我們你的* web.xml *文件嗎? – tmarwen 2014-09-02 09:13:12

回答

3

您的路徑不正確。如果你有一個正確的路徑,仍然有錯誤,那麼是一個映射錯誤。 但在這種情況下,您有404錯誤,這意味着路徑不存在。如果再有一個錯誤,你必須註冊,以映射的conf路徑中@Path("/test/rest/TestResultService/insertTestResult/")

然後:

你的路徑更改爲。

+0

我不知道我需要將ref bean添加到application-context.xml – david 2014-09-02 15:22:26