zoukankan      html  css  js  c++  java
  • SpringCloud Feign使用详解

    添加依赖:

    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-feign</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>


    创建启动类:

    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    import org.springframework.cloud.netflix.feign.EnableFeignClients;

    @EnableFeignClients
    @EnableDiscoveryClient
    @SpringBootApplication
    public class UserServiceApplication {

    public static void main(String[] args) {
    new SpringApplicationBuilder(UserServiceApplication.class).web(true).run(args);

    }
    }

    写一个feign client:

    @FeignClient(name = "这里写服务名称")
    public interface UserServiceAPI {

    @RequestMapping(value = "/user/getUserInfo", method = RequestMethod.GET)
    public BaseResponse<UserInfo> getUserInfo(@RequestParam("userId")Integer userId);

    测试:

    @RestController

    public class UserServiceAPITestController {

    @Autowired
    UserServiceAPI userServiceAPI;

    @RequestMapping(value = "/user/getUserInfo", method = RequestMethod.GET)
    public BaseResponse<KylinUserInfo> getUserInfoByUserId(Integer userId) {
    return userServiceAPI.getUserInfo(userId);
    }
    }

    浏览器访问:localhost:8080/user/getUserInfo

  • 相关阅读:
    Linux Xshell常用命令(项目部署)
    返回的数据转换成百分比分的方法
    百度分享插件
    vue请求中 post get传参方式是不同的哦
    Axios 中文使用
    关于iview ui的"Page分页"组件的使用
    Vue 实现前进刷新,后退不刷新的效果
    Vue框架Element UI教程-axios请求数据
    Spring学习总结(8)-接口多个实现类的动态调用
    Redis集群
  • 原文地址:https://www.cnblogs.com/gslblog/p/7238047.html
Copyright © 2011-2022 走看看