springcloud(二) - 服务调用Feign&openFeign

功能介绍:动态代理的方式,简化请求其他服务的开发成本,更好得对请求地址组装、接受返回信息、返回参数解析等

 

 Feign和OpenFeign区别:

OpenFeign实现了Feign的基础功能,同时支持springmvc的注解,比如@RequestMapping

 

功能实现

复制代码
<!--openfeign依赖-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

# application.yml
eureka:
  client:
    register-with-eureka: false
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/

//启动类
@SpringBootApplication
@EnableFeignClients
public class OrderFeignMain80 {

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


//可以调用
EUREKA-SUPPORT服务下面多个接口
@Configuration
@FeignClient(value = "EUREKA-SUPPORT")
public interface ISupportService {

@GetMapping("/support/say")
String say(@PathVariable("msg") int msg);

}
 
复制代码

openFeign还可以配置日志打印、自定义拦截器和超时时间设置

比如:connectTimeout连接超时,readTimeout读取超时

 

 参考地址: https://blog.csdn.net/qq_41539088/article/details/127681581

posted on   周公  阅读(55)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
历史上的今天:
2022-02-09 拦截器、过滤器
2021-02-09 Linux防火墙---Firewall

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示