Feign 客户端和参数获取

问题描述

这是我的配置类:

@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "partner.broker.agreements.rest-client")
public class brokerAgreementsRestConfig extends RestClientConfig {
    private String investApiKey;
}

我需要通过 FeignClient 发送获取请求。我的请求必须有一个带密钥的标头:

@FeignClient(name = "brokerAgreements",url = "${partner.broker.agreements.rest-client.baseUrl}")
public interface brokerAgreementsRestClient {

    String X_APP_HEADER = "x-app-name=bundle";
    String X_API_KEY = "x-api-key=%s";
    String X_INVEST_API = String.format(X_API_KEY,new brokerAgreementsRestConfig().getInvestApiKey());

    @GetMapping(path = "broker-account/siebel/{siebelId}",consumes = APPLICATION_FORM_URLENCODED_VALUE,headers = {X_APP_HEADER,X_INVEST_API})
    brokerAccountsRs getbrokerAccounts(@PathVariable(value = "siebelId") String siebelId,@RequestBody String requestBody);
}

但我的 IDE 说标题不正确,我的 X_INVEST_API 应该是一个常量。据我所知,在接口中初始化的所有对象都是最终的。出了什么问题,为什么它需要一个常量?

解决方法

我认为您必须使用具有动态值的标头,例如 question :