当前位置:网站首页>Feign source code analysis

Feign source code analysis

2022-04-23 08:04:00 Dream river dream

GitHub github = Feign.builder()
                         .decoder(new GsonDecoder())
                         .target(GitHub.class, "https://api.github.com");
public interface GitHub {
    

  @RequestLine("GET /repos/{owner}/{repo}/contributors")
  List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repository);

  class Contributor {
    
    String login;
    int contributions;
  }
}

It will generate Github Implementation class of interface , Let's find out

1)Feign.builder() Meeting new Out Feign An inner class feign.Feign.Builder;
2) adopt target Method , Package parameters as Target class , And then there was build Method
 Insert picture description here
 Insert picture description here
Top handle Contract Class into ParseHandlersByName in , Last new a
Feign Implementation class of interface
 Insert picture description here
 Insert picture description here

版权声明
本文为[Dream river dream]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230629086363.html