添加依赖:

<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

最新文章

  1. Java多线程学习(二)
  2. HttpContext的dynamic包装器DynamicHttpContext (附原代码)
  3. C# 多线程详解 Part.04(Lock、Monitor、生产与消费)
  4. JS-数组的方法
  5. POJ1985Cow Marathon[树的直径]
  6. classpath、path、JAVA_HOME的作用
  7. LPHW-积累-ex1-6
  8. eclipse插件开发中全局对象的获取
  9. ASP.NET程序读取二代身份证(附源码)
  10. Angular报错记录
  11. APP闪退问题
  12. List去重的实现
  13. 17、字符串转换整数 (atoi)
  14. 阿里巴巴开源的Asynchronous I/O Design and Implementation
  15. 【NOI2019模拟】搬砖
  16. FTP 其他设置
  17. 运行和控制Nginx——命令行参数和信号
  18. [转][C#]枚举的遍历Enum
  19. 深入理解python里面类的对象的赋值
  20. 微信小程序wxml文件中调用自定义函数

热门文章

  1. LNK4098: 默认库“MSVCRT”与其他库的使用冲突
  2. 面试题----寻找比一个N位数大的“下”一个数
  3. this 和 new 构造函数
  4. 介绍一款好用 mongodb 可视化工具
  5. Intellij导入子项目时,maven列表子项目灰色不可用---解决方法
  6. Cocoapods使用过程中遇到的问题
  7. 全新的.NET解释器 - Mono已经到来
  8. 一个ICON图标的转换程序
  9. C#导出EXCEL没有网格线的解决方法
  10. 搭建php环境的几种方法