1

我正在寻找一个如何从 NO-spring-boot 应用程序中使用 netflix-feign 的示例。我有一个现有的 SpringMVC (4.2) webapp。现在我用 Spring-boot + (eureka, feign) 构建了一些“微服务”,我想将它们用作 webapp 的后端服务。

提前致谢

4

1 回答 1

3

在 github 存储库中,您可以看到一些使用示例feign-client

基本上,您需要创建一个带有feign注释而不是的接口Spring,一个示例是(您可以在 github 页面中看到更多信息):

public interface YourClient {

     @RequestLine("POST /")
     @Headers("Content-Type: application/json")
     Response getSomething(@Param("id") String id);

}

然后要实例化你的 feign 客户端,它需要使用它的 builder Feign。它很简单,并且可以配置:

YourClient yourClient = Feign.builder()
                       .decoder(new GsonDecoder()) // you could use Gson, Jackson,...
                       .target(YourClient .class, "https://your.url");

然后你可以使用它来调用你想要的方法:

yourClient.getSomething("myId");
于 2016-10-28T09:33:14.810 回答