版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/c_royi/article/details/82967976
Feign学习
作用:实现接口访问数据的负载均衡
配置
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
client
1.FeignConfig
@Configuration
public class FeignConfig {
@Bean
// 当远程调用失败会进行重试
public Retryer feignRetryer(){
return new Retryer.Default(100,SECONDS.toMillis(1),5);
}
}
2.EurekaClientFeign(配置访问的client和FeignConfig)
@FeignClient(value = "eureka-client",configuration = FeignConfig.class)
public interface EurekaClientFeign {
@GetMapping("/hi")
public String sayHiFromClientEureka(@RequestParam(value = "name") String name);
}
启动类
注解@EnableFeignClients