我们知道要使用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.
Spring Cloud Feign源码解析
最新推荐文章于 2024-02-05 09:05:49 发布