java - Error Injecting FeignClient from another Project -


i having trouble auto wiring feign client project. appears implementation of feign client not being generated , injected.

this error getting.

org.springframework.beans.factory.beancreationexception:  error creating bean name 'passportrestcontroller': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception:  not autowire field: private com.wstrater.service.contacts.client.contactservice com.wstrater.service.passport.server.controllers.passportrestcontroller.contactservice; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception:  no qualifying bean of type [com.wstrater.service.contacts.client.contactservice] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations:  {@org.springframework.beans.factory.annotation.autowired(required=true)} 

the feign client pretty straight forward. have removed imports brevity.

package com.wstrater.service.contacts.client;  @feignclient("contact-service") public interface contactservice {    @requestmapping(method = requestmethod.get, value = contactconstants.contacts_user_id_path)   public collection<contact> contactsbyuserid(@pathvariable("userid") string userid);  } 

i added component scan project include application , it's controllers , include feign client in other project.

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);   }  } 

the rest controller of imports removed brevity.

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<passport> passportbyuserid(@pathvariable string userid) {     responseentity<passport> ret = null;      collection<contact> contacts = contactservice.contactsbyuserid(userid);     if (contacts == null || contacts.isempty()) {       ret = new responseentity(httpstatus.not_found);     } else {       ret = responseentity.ok(new passport(contacts));     }      return ret;   }  } 

i have tried defining feign client interface in different projects , different packages , have seen success when put in same package application. make believe component scan issue though including package in scan. keep feign client interface in shared project define reusable "contract" , each project have unique package structure instead of defining feign client application using it.

thanks, wes.

you need tell feign scanner locate interfaces.

you can use @enablefeignclients(basepackages = {"my.external.feign.client.package", "my.local.package"}).


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -