404 while using Spring cloud FeignClients -


this setup:

first service(flightintegrationapplication) invoke second service(baggageserviceapplication) using feignclients api , eureka.

project on github: https://github.com/idanfridman/bootnetflixexample

first service:

@springbootapplication @enablecircuitbreaker @enablediscoveryclient @componentscan("com.bootnetflix") public class flightintegrationapplication {      public static void main(string[] args) {         new springapplicationbuilder(flightintegrationapplication.class).run(args);     }  } 

in 1 of controllers:

    @requestmapping("/flights/baggage/list/{id}")     public string getbaggagelistbyflightid(@pathvariable("id") string id) {         return flightintegrationservice.getbaggagelistbyid(id);     } 

flightintegrationservice:

    public string getbaggagelistbyid(string id) {         uri uri = registryservice.getserviceurl("baggage-service", "http://localhost:8081/baggage-service");         string url = uri.tostring() + "/baggage/list/" + id;         log.info("getbaggagelist url: {}", url);          responseentity<string> resultstr = resttemplate.getforentity(url, string.class);         log.info("getproduct http-status: {}", resultstr.getstatuscode());         log.info("getproduct body: {}", resultstr.getbody());         return resultstr.getbody();      } 

registryservice:

@named public class registryservice {      private static final logger log = loggerfactory.getlogger(registryservice.class);       @autowired     loadbalancerclient loadbalancer;      public uri getserviceurl(string serviceid, string fallbackuri) {         uri uri;         try {             serviceinstance instance = loadbalancer.choose(serviceid);             uri = instance.geturi();             log.debug("resolved serviceid '{}' url '{}'.", serviceid, uri);          } catch (runtimeexception e) {             // eureka not available, use fallback             uri = uri.create(fallbackuri);             log.error("failed resolve serviceid '{}'. fallback url '{}'.", serviceid, uri);         }          return uri;     }  } 

and second service (baggage-service):

baggageserviceapplication:

@configuration @componentscan("com.bootnetflix") @enableautoconfiguration @enableeurekaclient @enablefeignclients public class baggageserviceapplication {       public static void main(string[] args) {         new springapplicationbuilder(baggageserviceapplication.class).run(args);     }  } 

baggageservice:

@feignclient("baggage-service") public interface baggageservice {      @requestmapping(method = requestmethod.get, value = "/baggage/list/{flight_id}")     list<string> getbaggagelistbyflightid(@pathvariable("flight_id") string flightid);   } 

baggageserviceimpl:

@named public class baggageserviceimpl implements baggageservice{  ....      @override     public list<string> getbaggagelistbyflightid(string flightid) {         return arrays.aslist("2,3,4");     }  } 

when invoking rest controller of flight integration service get:

2015-07-22 17:25:40.682  info 11308 --- [  xnio-2 task-3] c.b.f.service.flightintegrationservice   : getbaggagelist url: http://x230-ext_idanf:62007/baggage/list/4 2015-07-22 17:25:43.953 error 11308 --- [  xnio-2 task-3] io.undertow.request                      : ut005023: exception handling request /flights/baggage/list/4  org.springframework.web.util.nestedservletexception: request processing failed; nested exception org.springframework.web.client.httpclienterrorexception: 404 not found     @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:978) 

any idea ?

thanks, ray.

your code looks backwards me.

the feign client baggage service should declared in flight service , baggage service should have controller responds on url map in baggage service client, should not implement interface annotated @feignclient.

the setup have not have controller listening on /baggage/list/{flightid} in baggage service , no feign client in flight service - whole point of feign call methods on interface instead of manually handling urls, spring cloud takes care of auto-instantiating interface implementation , use eureka discovery.

try (or modify fits real world app):

flight service:

flightintegrationservice.java:

@component public class flightintegrationservice {      @autowired     baggageservice baggageservice;      public string getbaggagelistbyid(string id) {         return baggageservice.getbaggagelistbyflightid(id);     } } 

baggageservice.java:

@feignclient("baggage-service") public interface baggageservice {      @requestmapping(method = requestmethod.get, value = "/baggage/list/{flight_id}")     list<string> getbaggagelistbyflightid(@pathvariable("flight_id") string flightid);    } 

baggage service:

baggagecontroller.java:

@restcontroller public class baggagecontroller {      @requestmapping("/baggage/list/{flightid}")     public list<string> getbaggagelistbyflightid(@pathvariable string flightid) {         return arrays.aslist("2,3,4");     } } 

remove baggageservice.java , baggageserviceimpl.java baggage service


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -