2

Given the following code sample

-- client library code

@FeignClient("string-service")
public interface StringClient {

     @RequestMapping(method = RequestMethod.GET, value = "/microservicestring")
      public String home();
}


@Service
public class StringHystrixClient {

    private final SpringClient springClient;
//....

}

-- service library code

@RestController
public class StringController implements StringClient {
    public String home(){
         return "World";
    }
}


@SpringBootApplication
@EnableHystrix
@EnableEurekaClient
@EnableFeignClients
public class StringApplication { ....}

If the service library references the client library, when the application gets started, through component scanning we will get to a state where in filling the dependencies from StringHystrixClient, the spring container will not know what to do because there are two beans implementing StringClient.

One solution to avoid this would be to not implement the StringClient in the StringController, but the code duplication from the interface and the rest controller would be error prone. Can somebody point out a more elegant solution to this problem?

marius_neo
  • 1,535
  • 1
  • 13
  • 28
  • I see a question that is very similar to this one : http://stackoverflow.com/questions/29284911/can-a-spring-cloud-feign-client-share-interface-with-an-spring-web-controller – marius_neo Jul 08 '15 at 13:11
  • why is the controller in clients dependencies? You should probably only distribute the `@FeignClient` to clients. – spencergibb Jul 08 '15 at 17:47
  • I'm mistaken, you are referencing the client from the server. Can you exclude the FeignClient from component scanning? Or not include it in the server? – spencergibb Jul 08 '15 at 17:50
  • Yes, the component scan can exclude the `@FeignClient`, but this is not ideal (in case that multiple `@FeignClient` instances share the same package across different projects and some of them are needed as dependencies of the StringApplication). – marius_neo Jul 15 '15 at 04:39

0 Answers0