title: Error Injecting FeignClient from another Project
body: <p>I am having trouble auto wiring a feign client from another project. It appears that the implementation of the feign client is not being generated and injected.</p>
  
  <p>This is the error I am getting.</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'passportRestController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
  Could not autowire field: private com.wstrater.service.contacts.client.ContactService com.wstrater.service.passport.server.controllers.PassportRestController.contactService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
  No qualifying bean of type [com.wstrater.service.contacts.client.ContactService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 
  {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  </code></pre>
  
  <p>The feign client is pretty straight forward. I have removed the imports for brevity.</p>
  
  <pre><code>package com.wstrater.service.contacts.client;
  
  @FeignClient("contact-service")
  public interface ContactService {
  
    @RequestMapping(method = RequestMethod.GET, value = ContactConstants.CONTACTS_USER_ID_PATH)
    public Collection&lt;Contact&gt; contactsByUserId(@PathVariable("userId") String userId);
  
  }
  </code></pre>
  
  <p>I added the component scan to my project to include the application and it's controllers and to include the feign client in the other project.</p>
  
  <pre><code>package com.wstrater.service.passport.server;
  
  @EnableEurekaClient
  @EnableFeignClients
  @SpringCloudApplication
  @ComponentScan({"com.wstrater.service.passport.server",
                  "com.wstrater.service.contacts.client"})
  public class PassportServiceApplication {
  
    public static void main(String[] args) {
      ApplicationContext ctx = SpringApplication.run(PassportServiceApplication.class, args);
    }
  
  }
  </code></pre>
  
  <p>The rest controller with most of the imports removed for brevity.</p>
  
  <pre><code>package com.wstrater.service.passport.server.controllers;
  
  import com.wstrater.service.contacts.client.ContactService;
  
  @RestController
  public class PassportRestController {
  
    @Autowired
    private ContactService contactService;
  
    @RequestMapping(PassportContstants.PASSPORT_USER_ID_PATH)
    public ResponseEntity&lt;Passport&gt; passportByUserId(@PathVariable String userId) {
      ResponseEntity&lt;Passport&gt; ret = null;
  
      Collection&lt;Contact&gt; contacts = contactService.contactsByUserId(userId);
      if (contacts == null || contacts.isEmpty()) {
        ret = new ResponseEntity(HttpStatus.NOT_FOUND);
      } else {
        ret = ResponseEntity.ok(new Passport(contacts));
      }
  
      return ret;
    }
  
  }
  </code></pre>
  
  <p>I have tried defining the feign client interface in different projects and different packages and have only seen success when it put it in the same package as the application. This make be believe that it is a component scan issue even though I am including the package in the scan. I would like to keep the feign client interface in a shared project to define a reusable "contract" and for each project to have a unique package structure instead of defining the feign client with the application using it.</p>
  
  <p>Thanks, Wes.</p>