title: Programmatically retrieve URL called by Spring FeignClient
body: <p>I'm trying to find a way to retrieve the URL that is currently mapped by Feign Client method interface in a Spring app, but I could not find a solution yet. The following code works:</p>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
    &lt;artifactId&gt;spring-cloud-starter-openfeign&lt;/artifactId&gt;
    &lt;version&gt;2.1.1.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>application.yml</p>
  
  <pre><code>api:
    url: https://jsonplaceholder.typicode.com
  </code></pre>
  
  <p>ApiClient.class</p>
  
  <pre><code>package com.example.feign;
  
  import org.springframework.cloud.openfeign.FeignClient;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.GetMapping;
  
  @FeignClient(name = "json-placeholder", url = "${api.url}")
  public interface ApiClient {
  
      @GetMapping(value = "/posts", consumes = "application/json")
      ResponseEntity&lt;String&gt; getPosts();
  }
  </code></pre>
  
  <p>FeignApplication.class</p>
  
  <pre><code>package com.example.feign;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.cloud.openfeign.EnableFeignClients;
  
  import javax.annotation.PostConstruct;
  
  @EnableFeignClients
  @SpringBootApplication
  public class FeignApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(FeignApplication.class, args);
      }
  
      @Autowired
      private ApiClient apiClient;
  
      @PostConstruct
      public void test() {
  
          // this works
          System.out.println(apiClient.getPosts().getBody());
  
          // apiClient. ... getPosts request URL
      }
  }
  </code></pre>
  
  <p>I tried to compose this URL reading directly from annotations, but it doesn't seem to work. Can anybody give me an alternative? Thank you.</p>
  
  <ul>
  <li>EDIT notes - </li>
  </ul>
  
  <p>Sorry, but I had do a small change in my question, due to an unexpected problem while applying provided solutions.</p>
  
  <p>Reading directly from Annotations works if the value set in annotation property is literal. If the value is read from application.yml file, the URL returned by the annotation property is the expression ifself, not the parsed value.</p>
  
  <p>Any ideas about this updated scenario? What I need is the URL actually been called by FeignClient. I'm understands all provided solutions are actually workarounds.</p>