Spring Boot项目集成OpenFeign

发布时间 2023-07-15 11:30:08作者: 摆烂ing
  1. 在pom.xml文件中加入openfeign依赖
<!-- 服务调用feign -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
  1. 定义Feign接口,使用@FeignClient注解指定服务提供方服务名称(如果使用nacos,就是nacos注册中心中微服务的名称)
@FeignClient(value = "service-product")
public interface CategoryFeignClient {
    // 远程调用微服务的接口信息
	@GetMapping(value = "/api/inner/product/category/trees")
    public Result<List<CategoryVo>> findAllCategory();
}
  1. 在启动类上使用@EnableFeignClients开启Feign的功能支持