我正在尝试构建一个简单的应用程序,该应用程序使用quarkus-rest-client. 我必须注入一个 API 密钥作为标头,这对于 API 的所有资源都是相同的。所以我想把这个 API Key 的值(取决于环境dev/qa/prod)放在application.properties位于src/main/resources.
我尝试了不同的方法来实现这一目标:
com.acme.Configuration.getKey到@ClientHeaderParamvalue 属性最后,我找到了下面描述的方法来使它工作。
我的问题是:有没有更好的方法来做到这一点?
这是我的代码:
@Path("/stores")
@RegisterRestClient
@ClientHeaderParam(name = "ApiKey", value = "{com.acme.Configuration.getStoresApiKey}")
public interface StoresService {
@GET
@Produces("application/json")
Stores getStores();
}
Run Code Online (Sandbox Code Playgroud)
@ApplicationScoped
public class Configuration {
@ConfigProperty(name = "apiKey.stores")
private String storesApiKey;
public String getKey() {
return storesApiKey;
}
public static String getStoresApiKey() {
return CDI.current().select(Configuration.class).get().getKey(); …Run Code Online (Sandbox Code Playgroud)