标签:enabled value 并且 boot img inf 一个 均衡 mapping
Feign是一个http请求调用的轻量级框架 可以使用Java接口注解的方式调用Http请求
Feign采用了声明式API 接口的风格 客户端调用过程变得简单
新建工程(继承父工程)
导入依赖
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency> </dependencies>
添加配置文件
server: port: 8008 eureka: instance: hostname: feign-client client: service-url: defaultZone: http://eureka01:8001/eureka/ register-with-eureka: true spring: application: name: eureka-fegin-client ribbon: eureka: enabled: true
创建一个接口
// FeginClient 客户端 value 为远程调用的实例名
@FeignClient(value = "eureka-client") public interface EurekaClientFeign { @GetMapping(value = "/hi/{name}") String sayHi(@PathVariable(value = "name") String name); }
添加代码
@RestController public class HiController { @Autowired EurekaClientFeign eurekaClientFeign; @GetMapping("/test") public String sayHi(){ return eurekaClientFeign.sayHi("sss"); } }
依次启动
打开浏览器访问
刷新
Feign 远程调用了eureka_client服务 并且有负载均衡的能力。
标签:enabled value 并且 boot img inf 一个 均衡 mapping
原文地址:https://www.cnblogs.com/chenziyue/p/12485478.html