必需的字符串不存在:弹簧休息模板



我正在尝试使用(GET(休息服务。

http://localhost:7010/abc/status?configFilePath=config%2Fconfig.properties

我正在尝试使用Spring RestTemplate服务使用它

下面是我用于 restTemplate 的代码:

String configFile = "config/config.properties";
Map<String,String> restvars = new HashMap<String,String>();
restvars.put("configFilePath", configFile);
RestTemplate restTemplate = new RestTemplate();
String restUrl = http://localhost:7010/abc/status?          
String restCall = restTemplate.getForObject(restUrl, String.class, restvars);
System.out.println(restCall.toString());

它抛出

Required String parameter 'configFilePath' is not present

地图实际上没有传递参数吗?

我从错误的角度看它。这个SO问题的答案有所帮助。

HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
        .queryParam("configFilePath", configFile);
HttpEntity<?> entity = new HttpEntity<>(headers);
HttpEntity<String> response = restTemplate.exchange(builder.toUriString(),String.class);

最新更新