2

I'm trying to inject a property from my application.properties as a baseUri in my ServiceClient. This is my ServiceClient:

@Path("/products/v2")
@Produces(MediaType.APPLICATION_JSON)
@RegisterRestClient(baseUri = "url...")
public interface ProductServiceClient {

    @GET
    @Path("/search")
    String searchProducts();
}

What I've tried:

I can't use @ConfigProperty as noted here: https://quarkus.io/guides/config#using-configproperties, because Java tells me the types are incompatible:

@RegisterRestClient(baseUri = @ConfigProperty(name = "base.url"))

"Incompatible types. Found: 'org.eclipse.microprofile.config.inject.ConfigProperty', required: 'java.lang.String'"

I've also tried to programattically access the property as said here: https://quarkus.io/guides/config#programmatically-access-the-configuration

@RegisterRestClient(baseUri = ConfigProvider.getConfig().getValue("base.url", String.class))

This doesn't work because Java tells me that the "Attribute value must be constant".

I've also tried this which didn't work for me either: Quarkus & Microprofile : Is there a better way to use a property from application.properties into @ClientHeaderParam?

How can I inject a property from my application.properties/application.yaml file as a baseUri in @RegisterRestClient?

Stef
  • 185
  • 4
  • 15

1 Answers1

3

Take a look at https://download.eclipse.org/microprofile/microprofile-rest-client-2.0/microprofile-rest-client-spec-2.0.html#mpconfig or the quickstart at https://github.com/quarkusio/quarkus-quickstarts/tree/master/rest-client-quickstart for examples on how the property key needs to be defined.

BaseURI can be automatically set with configuration by setting a key named {package}.ProductServiceClient/mp-rest/url={value}. There is no need to set a property on @RegisterRestClient with this configuration.

Ken
  • 835
  • 4
  • 11
  • Wow. I read the guide but at first didn't understand what /mp-rest/ meant and figured it was for something else. This worked great, thanks. – Stef Dec 23 '20 at 14:31