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
分类:
SpringCloud
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有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