首页 > 解决方案 > 为什么我得到异常 - 没有足够的变量可用于在 Spring Rest URI 调用中扩展?

问题描述

我正在处理与付款相关的休息 API 调用。但我遇到了一个例外。我知道这是由于将参数设置为 rest uri。

String uri = "https://test-gateway.mastercard.com/api/rest/version/52/merchant/{merchantId}/order/{orderId}/transaction/{transactionId}";
LinkedMultiValueMap<String, String> uriVars = new LinkedMultiValueMap<>();
    uriVars.add("merchantId", _paymentInstrument.getAcquirerMid());
    uriVars.add("orderId", _paymentInstrument.getOrderId().toString());
    uriVars.add("transactionId", _paymentInstrument.getTargetTransactionId().toString());
    String uri = UriComponentsBuilder.fromHttpUrl(url)
            .queryParams(uriVars).build().toUriString();
    VoidRequest voidRequest = 
createVoidRequest(_paymentInstrument.getTargetTransactionId());
    HttpEntity<VoidRequest> requestEntity = new HttpEntity<>(voidRequest, headers); 
ResponseEntity<TransactionResponse> responseEntity = restTemplate.exchange(uri, HttpMethod.PUT, requestEntity, TransactionResponse.class);

我得到的异常是在 Spring 中使用 RestTemplate。异常 - 没有足够的变量可用于扩展“merchantId”。

标签: springrestencodeuricomponent

解决方案


推荐阅读