Spring系列学习之Spring Cloud OpenFeign声明性HTTP REST客户端
2018-12-25 20:55
746 查看
英文原文:https://spring.io/projects/spring-cloud-openfeign
目录
概述
该项目通过自动配置和Spring环境以及其他Spring编程模型习惯用法为Spring Boot应用程序提供OpenFeign集成。
特性
- 声明性REST客户端:Feign创建使用JAX-RS或Spring MVC注释修饰的接口的动态实现
入门
@SpringBootApplication @EnableFeignClients public class WebApplication { public static void main(String[] args) { SpringApplication.run(WebApplication.class, args); } @FeignClient("name") static interface NameService { @RequestMapping("/") public String getName(); } }
[code]package demo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static org.springframework.web.bind.annotation.RequestMethod.GET; /** * @author Spencer Gibb */ @SpringBootApplication @EnableDiscoveryClient @RestController @EnableFeignClients public class HelloClientApplication { @Autowired HelloClient client; @RequestMapping("/") public String hello() { return client.hello(); } public static void main(String[] args) { SpringApplication.run(HelloClientApplication.class, args); } @FeignClient("HelloServer") interface HelloClient { @RequestMapping(value = "/", method = GET) String hello(); } }
快速开始
使用Spring Initializr引导您的应用程序。
学习
文档
每个Spring项目都有自己的; 它详细解释了如何使用项目功能以及使用它们可以实现的功能。
2.1.0 RC3 PRE CURRENT | Reference Doc. | API Doc. |
2.0.3 SNAPSHOT CURRENT | Reference Doc. | API Doc. |
2.0.2 CURRENT GA | Reference Doc. | API Doc. |
示例
尝试一些例子:
阅读更多相关文章推荐
- Spring Cloud 入门教程(六): 用声明式REST客户端Feign调用远端HTTP服务
- SpringCloud——声明性REST客户端(Feign)
- 疯狂Spring Cloud连载(10)REST客户端Feign介绍
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务的方法(推荐)
- 微服务框架Spring Cloud介绍 Part4: 使用Eureka, Ribbon, Feign实现REST服务客户端
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- Spring Cloud Feign作为HTTP客户端调用远程HTTP服务,feign熔断器
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- spring cloud学习——17. Declarative REST Client: Feign
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- Spring-Cloud学习笔记(二)RestTemplate和Feign的使用方式以及部分注解的使用
- 疯狂Spring Cloud连载(10)——Rest客户端Feign介绍
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- springcloud 的学习(三) feign