当前位置: 代码迷 >> 综合 >> spring-cloud,FeignClient的坑--status 404 reading HelloRemote
  详细解决方案

spring-cloud,FeignClient的坑--status 404 reading HelloRemote

热度:17   发布时间:2023-11-03 07:52:29.0

消费者调用生产者的服务报错,status 404 reading HelloRemote...

排除掉书写和格式错误后,最可能的原因如下

生产者配置文件配置了项目的context-path

server:port: 8085tomcat:uri-encoding: UTF-8servlet:context-path: /testPath

context-path的属性如果配置后,需要在你的消费者配置同样的属性!!!

错误例子:

//生产者
server:port: 8086tomcat:uri-encoding: UTF-8servlet:context-path: /testPath//消费者
@FeignClient(name= "test")
public interface HelloRemote {@RequestMapping(value = "/hello",method= RequestMethod.GET)public String hello(@RequestParam(value = "name") String name);
}

正确例子:

//生产者
server:port: 8086tomcat:uri-encoding: UTF-8servlet:context-path: /testPath//消费者
@FeignClient(name= "test",path="/testPath")//修改此处!!!
public interface HelloRemote {@RequestMapping(value = "/hello",method= RequestMethod.GET)public String hello(@RequestParam(value = "name") String name);
}

除此以外,可以不配置生产者的 context-path属性,消费者消费时就不用增加path参数!!!

 

 

 

  相关解决方案