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

  • 相关阅读:
    7款纯CSS3实现的炫酷动画应用
    9款基于HTML5/SVG/Canvas的折线图表应用
    8款耀眼的jQuery/HTML5焦点图滑块插件
    10款很酷的HTML5动画和实用应用 有源码
    13款精彩实用的最新jQuery插件
    9款超绚丽的HTML5/CSS3应用和动画特效
    8款最受欢迎的HTML5/CSS3应用及源码
    Zookeeper可以干什么
    MySQL数据库优化
    SQL语句的执行过程
  • 原文地址:https://www.cnblogs.com/gslblog/p/7238047.html
Copyright © 2011-2022 走看看