Spring Cloud Feign源码解析

  我们知道要使用feign,需要在springboot启动类放入@EnableFeignClients开关来打开feign的使用。
  
  @EnableFeignClients
  
  @EnableZuulProxy
  
  @EnableDiscoveryClient
  
  @SpringBootApplication
  
  public class GatewayApplication {
  
  public static void main(String[] args) {
  
  SpringApplication.run(GatewayApplication.class, args);
  
  然后会使用例如
  
  @FeignClient("user-center")
  
  public interface UserClient {
  
  @PostMapping("/users-anon/finduser")
  
  LoginAppUser findUserByName(@RequestParam("username") String username);
  
  }
  
  现在我们可以考虑的方向是打上了@FeignClient("user-center")标签后,UserClient接口是如何被实例化成对象的,然后是在Controller中调用UserClient对象是如何进行网络请求的。
  
  @Slf4j
  
  @RestController
  
  public class TokenController {
  
  @Autowired
  
  private Oauth2Client oauth2Client;
  
  @Autowired
  
  private UserClient userClient;
  
  /**
  
  * 系统登陆<br>
  
  * 根据用户名登录<br>
  
  * 采用oauth2密码模式获取access_token和refresh_token
  
  *
  
  * @param username
  
  * @param password
  
  * @return
  
  */
  
  @SuppressWarnings("unchecked")
  
  @PostMapping("/sys/login")
  
  public Result<Map> login(@RequestParam String username,@RequestParam String password) {
  
  Map<String, String> parameters = new HashMap<>();
  
  parameters.put(OAuth2Utils.GRANT_TYPE, "password");
  
  parameters.put(OAuth2Utils.CLIENT_ID, "system");
  
  parameters.put( www.chenghylpt.com "client_secret", "system");
  
  parameters.put(OAuth2Utils.SCOPE, "app");
  
  // parameters.put(www.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值