Search code examples
javamicronaut

Obtaining a Micronaut HttpClient with url from property


I want to obtain the HttpClient by the Client annotation, so it is managed by Micronaut. However this way I can't use a url from my property file:

public FooService(
   @Value("${url}") String url,
   // I can't use url here, but @Client needs an non empty url parameter
   @Client(url) RxHttpClient httpClient
   // other constructor arguments...
)

Is there to let Micronaut manage the HttpClient while still using a url from my application.yml?


Solution

  • You could inject the url from your properties using:

    @Client("${myproperties.url}")
    RxWebSocketClient webSocketClient;
    

    See: https://docs.micronaut.io/latest/guide/httpClient.html