java spring call rest webservice error 404

时间:2018-03-22 15:00:31

标签: java spring rest

嗨,当我打电话给休息网络服务时,我收到错误404

网络服务方法是:

 @RequestMapping(value = "/natlist", produces = "application/json", method = RequestMethod.GET)
public ResponseEntity<List<Nacionalidades>> getnatlist() 
{
     List<Nacionalidades> nacionalidadesList = new ArrayList<>();
        .....
     return new ResponseEntity<>(nacionalidadesList, HttpStatus.OK);

}

对Web服务的调用

 ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault());
     RestTemplate restTemplate = new RestTemplate(requestFactory);
     try
     {
        ResponseEntity<Nacionalidades[]> responseEntity = restTemplate.getForEntity(url, Nacionalidades[].class);
        HttpStatus statusCode = responseEntity.getStatusCode();
        if (statusCode == HttpStatus.OK)
        {
            Nacionalidades[] natArr = responseEntity.getBody();
            ....        
        }
    }

网络服务方法是:

enter code here

1 个答案:

答案 0 :(得分:0)

你不应该使用路径参数而不是值吗?你试过这个吗?

@RequestMapping(path = "/natlist", produces = "application/json", method = RequestMethod.GET)