title: Autowiring a Feign client in my controller when spring launching throws exception
body: <p>I already tried solutions on <a href="https://stackoverflow.com/questions/43093968/enablefeignclients-and-feignclient-fail-on-autowiring-feigncontext-nosuchbea">this</a> and <a href="https://github.com/spring-projects/spring-boot/issues/7270" rel="nofollow noreferrer">this</a> but no success so maybe I'm missing something else</p>
  <p>here is my architecture</p>
  <p>I have a ressource micro-service protected by Oauth2 which is implementing my business logic and a client micro-service with a thymleaf template that is consuming this ressource. Using Oauth2RestTemplate is fine now i m trying to use feign.</p>
  <p>first here is my ressource project resume</p>
  <p>Application.yml</p>
  <pre><code>spring.application.name: COMPONENTS
  
  server:
    port: 0
  
  
    
  eureka.client.service-url.defaultZone: xxxxxxxxxxxxxxxxxxxxxxxx
  
  security.oauth2.resource.token-info-uri: xxxxxxxxxxxxxxxxxxxxxx
  security.oauth2.client.client-id: xxxxxxxxxxxxxx
  security.oauth2.client.client-secret: xxxxxxxxxxxxx
  
  spring.jackson.date-format: com.fasterxml.jackson.databind.util.ISO8601DateFormat
  
  
  spring:
    datasource:
      url: jdbc:mariadb://localhost:3306/pos_auth?createDatabaseIfNotExist=true
      username: root
      password: xxxxxxxx
      driver-class-name: org.mariadb.jdbc.Driver
  </code></pre>
  <p>And a simple Controller</p>
  <pre><code>@Controller
  @RequestMapping(ApplicationController.API)
  public class ApplicationController {
      
      public static final String API = &quot;applications&quot;;
      
      @Autowired
      private ComponentsService componentsService;
      
      @GetMapping
      public ResponseEntity&lt;List&lt;Apps&gt;&gt; getApplicationsList() {
          return new ResponseEntity&lt;List&lt;Apps&gt;&gt;(componentsService.getAllApps(), HttpStatus.OK);
      }
  
      
  }
  </code></pre>
  <p>Now here is My client important part of Feign client implementation</p>
  <p>the main class</p>
  <pre><code>@SpringBootApplication
  @EnableOAuth2Sso
  @EnableEurekaClient
  @EnableDiscoveryClient
  @EnableWebSecurity
  public class ClientApplication extends WebSecurityConfigurerAdapter{
  
  
      public static void main(String[] args) {
          SpringApplication.run(ClientApplication.class, args);
      }
      
      
          @Override
          protected void configure(HttpSecurity http) throws Exception {
              http
                      .logout()
                      .logoutSuccessUrl(&quot;http://localhost:9999/uaa/exit&quot;);
              http.authorizeRequests().antMatchers(&quot;/graphics/**&quot;).permitAll().
                      and().authorizeRequests().anyRequest().authenticated();
          }
     
  
      @Bean
      @LoadBalanced
      OAuth2RestTemplate oauth2RestTemplate(OAuth2ClientContext oauth2ClientContext, OAuth2ProtectedResourceDetails details) {
          return new OAuth2RestTemplate(details, oauth2ClientContext);
      }
  
      @Profile(&quot;!cloud&quot;)
      @Bean
      RequestDumperFilter requestDumperFilter() {
          return new RequestDumperFilter();
      }
  
  }
  </code></pre>
  <p>A feign configuration</p>
  <pre><code>@Configuration
  @EnableFeignClients
  @ImportAutoConfiguration({RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class, FeignAutoConfiguration.class})
  public class FeignConfig {
  
  }
  </code></pre>
  <p>My desired behaviour in the client controller when index is called</p>
  <pre><code>@Controller
  public class MessageController {
  
      @Autowired
      OAuth2RestTemplate restTemplate;
  
      
      @Autowired
      private AppClientFeign appClientFeign;
  
  
      @RequestMapping(&quot;/&quot;)
      String home(Model model) {
          model.addAttribute(&quot;applications&quot;, appClientFeign.getApps());
          System.out.println(appClientFeign.getApps());
          return &quot;index&quot;;
      }
  
    
  }
  </code></pre>
  <p>finally my feign client</p>
  <pre><code>@FeignClient(&quot;COMPONENTS&quot;)
  public interface AppClientFeign {
      @RequestMapping(method = RequestMethod.GET, value = &quot;/applications&quot;)
      List&lt;App&gt; getApps();
  }
  </code></pre>
  <p>while running the  client I m getting the following exception</p>
  <blockquote>
  <p>Field appClientFeign in demo.MessageController required a bean of type
  'org.springframework.cloud.netflix.feign.FeignContext' that could not
  be found.</p>
  <ul>
  <li>Bean method 'feignContext' not loaded because @ConditionalOnClass did not find required class 'feign.Feign'</li>
  </ul>
  </blockquote>