david
david

Reputation: 761

Spring error - springframework.web.client.HttpClientErrorException: 404 Not Found

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:

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:

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?

Upvotes: 14

Views: 136918

Answers (2)

CodeWorld
CodeWorld

Reputation: 2307

Above answer gave me a direction!
If you get this error while calling one microservice from another and you have implemented concept of context path for microservices.
Consider providing context path as well, as part of microservice endpoint while making call.

Upvotes: 0

hurricane
hurricane

Reputation: 6734

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.

Change your path to : @Path("/test/rest/TestResultService/insertTestResult/")

Then if you have an error again you have to register your path to mapping conf.

Upvotes: 14

Related Questions