springcloud如何使用openfeign呢?
下文笔者讲述SpringCloud使用openFeign的方法及示例分享,如下所示
Spring Cloud使用openFeign的实现思路
1.引入相应的依赖 2.编写相应的接口 3.服务调用相应的接口,即可实现openfeign的使用例:Spring Cloud使用feign的示例
引入openfeign依赖
pom文件中加入相应的坐标信息
<!-- OpenFeign组件 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
定义相应的服务
@FeignClient(value = "test-service-feign", path = "/testController")
public interface TemplateService {
@GetMapping("/getUserInfo")
UserInfo getUser(@RequestParam("id") Long id);
}
服务的引用
@Autowired private TemplateService tempService; tempService.getUser(100);
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


