0%

OpenFeign简介

OpenFeign简介

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

依赖

1
2
3
4
5
<!-- openFeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

配置启动类

1
2
3
4
5
6
7
8
9
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients // 开启feign
public class ConsumerApp {

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

feign接口编写

1
2
3
4
5
6
@FeignClient(value = "SPRINGCLOUD2-PROVIDER")
public interface DeptClient {

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

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