OpenFeign简介

OpenFeign是SpringCloud对于Feign进行的再次封装,使其支持了SpringMVC的标准注解以及HttpMessageConverters

依赖

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

<!-- more -->

配置启动类

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients   // 开启feign
public class ConsumerApp {

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApp.class,args);
    }
}

feign接口编写

@FeignClient(value = "SPRINGCLOUD2-PROVIDER")
public interface DeptClient {

    @GetMapping(value = "/dept/get/{id}")
    CommonResult<Dept> get(@PathVariable("id") long id);
}

直接调用该方法就可以调用该微服务的接口

参考文献


bug生产者
20 声望0 粉丝