SpringCloud使用Feign对接第三方http接口

/ Java / 没有评论 / 5040浏览

SpringCloud使用Feign对接第三方http接口

1.依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

2.写客户端去请求

/**
* 查询楼层列表
* @return
*/
@RequestMapping(value = "space/list", method = RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE)
Result<List<SFlatInfoDto>> getFlatList(
    @RequestBody SFlatInfoDto dto
);

3.在客户端上加注解

@FeignClient(url = "${fegin-inter-api.flatUrl}", name = "flatUrl")

4.action里面调用

先引入client

@Autowired
private SFlatInfoFeign sFlatInfoFeign;
//直接调用即可
sFlatInfoFeign.getFlatList(sFlatInfoDto);