title: Openfeign + Spring cloud : Field required a bean of type that could not be found
body: <p>I have a problem with spring and openfeign in which I think you can help me.</p>
  <p>I have a pom file as follows:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;xx.yyy&lt;/groupId&gt;
      &lt;artifactId&gt;component&lt;/artifactId&gt;
      &lt;version&gt;1.0.0&lt;/version&gt;
      &lt;name&gt;component&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;maven-jar-plugin.version&gt;3.1.1&lt;/maven-jar-plugin.version&gt;
          &lt;pact.version&gt;3.6.7&lt;/pact.version&gt;
          &lt;spring-cloud.version&gt;Greenwich.SR4&lt;/spring-cloud.version&gt;
      &lt;/properties&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.10.RELEASE&lt;/version&gt;
          &lt;relativePath /&gt;
      &lt;/parent&gt;
  
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-amqp&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jetty&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-openfeign&lt;/artifactId&gt;
          &lt;/dependency&gt;
  ......
  &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
                  &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  ......
  </code></pre>
  <p>I have declared in the main class the following configurations:</p>
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication(scanBasePackages = {&quot;xx.yyy&quot;, &quot;xx.yyy.rest.client&quot;}, exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
  @EnableAsync
  @Import({P2OrchestratorApplicationConfig.class})
  public class P2OrchestratorApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(P2OrchestratorApplication.class, args);
      }
  }
  </code></pre>
  <p>I have a custom feign configuration class:</p>
  <pre><code>@Configuration
  @EnableFeignClients()
  @ImportAutoConfiguration({FeignAutoConfiguration.class})
  public class FeignConfig {
  
      @Bean
      public OkHttpClient client() {
          return new OkHttpClient();
      }
      
      @Bean
      public Logger.Level feignLoggerLevel() {
          return Logger.Level.FULL;
      }
      
      @Bean
      public Contract feignContract() {
          return new feign.Contract.Default();
      }
  }
  </code></pre>
  <p>I have a open feign client as follow:</p>
  <pre><code>@FeignClient(name=&quot;legacyClient&quot;, value = &quot;legacyClient&quot;, url = &quot;${uri.microservice.legacy}&quot;, configuration = FeignConfig.class)
  public interface LegacyClient {
      
      @PatchMapping(value = &quot;/legacy/xxx/cleanLine/{authorizationCode}&quot;, produces = { MediaType.APPLICATION_JSON_VALUE })
      public ResponseEntity&lt;Boolean&gt; cleanLine(@PathVariable(&quot;authorizationCode&quot;) Long authorizationCode, @RequestParam(required = true) Long lineNumber);
      
  
  }
  </code></pre>
  <p>and finally a Component in which I need to use this client:</p>
  <pre><code>@Log4j
  @Component(&quot;p2ProcessAlgorithm&quot;)
  public class P2ProcessAlgorithm {
  
  @Autowired
  @Qualifier(&quot;legacyClient&quot;)
  private LegacyClient legacyClient;
  
  public final void process(){
  
  Long authorizationCode = 123L;
  Long lineNumber = 1L;
  Boolean isClean= this.legacClient.cleanLine(authorizationCode, lineNumber);
  ......
  }
  </code></pre>
  <p>But the app give me the next message:</p>
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field legacyClient in xxx.yyy.p2.structure.P2ProcessAlgorithm required a bean of type 'xxx.yyy.rest.client.LegacyClient' that could not be found.
  
  The injection point has the following annotations:
      - @org.springframework.beans.factory.annotation.Autowired(required=true)
      - @org.springframework.beans.factory.annotation.Qualifier(value=p2AsyncOrchestratorService)
  
  
  Action:
  
  Consider defining a bean of type 'xxx.yyy.rest.client.LegacyClient' in your configuration.
  </code></pre>
  <p>I've tried several configurations but I can't get the openfeign client to be a recognized bean in the P2ProcessAlgorithm class.</p>
  <p>Do you have any idea?</p>
  <p>Thanks in advance</p>