使用Feign接口调用其它服务出现404异常

使用Feign接口调用其它服务出现404异常
我在使用Feign接口调用其它服务的时候,报了如下错误

2021-07-27 10:00:33.239 ERROR 8560 --- [nio-8082-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/backend-order] threw exception [Request processing failed; nested exception is feign.FeignException$NotFound: [404] during [GET] to [http://backend-shipping/shipping/1] [ShippingFeign#findById(Integer)]: [<!doctype html><html lang="en"><head><title>HTTP Status 404Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} ... (431 bytes)]] with root cause

feign.FeignException$NotFound: [404] during [GET] to [http://backend-shipping/shipping/1] [ShippingFeign#findById(Integer)]: [<!doctype html><html lang="en"><head><title>HTTP Status 404Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} ... (431 bytes)]
	at feign.FeignException.clientErrorStatus(FeignException.java:201)
	at feign.FeignException.errorStatus(FeignException.java:177)
	at feign.FeignException.errorStatus(FeignException.java:169)
	at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:92)
	at feign.AsyncResponseHandler.handleResponse(AsyncResponseHandler.java:96)
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:138)
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:89)
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100)
	at com.sun.proxy.$Proxy123.findById(Unknown Source)
	at com.aiun.order.service.impl.OrderServiceImpl.assembleOrderVo(OrderServiceImpl.java:324)
	at com.aiun.order.service.impl.OrderServiceImpl.createOrder(OrderServiceImpl.java:82)
	at com.aiun.order.controller.OrderController.create(OrderController.java:48)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
.......	

发现是没有找到,应该是路径的问题,经过一番检查发现我的收货地址模块配置了项目的访问路径

server:
 port: 8085                  # 项目访问端口
 servlet:
  context-path: /backend-shipping    # 项目访问路径

但是我的Feign接口写的是这样的

@FeignClient(value = "backend-shipping")
@RequestMapping("/shipping/")
public interface ShippingFeign {
    @GetMapping("{id}")
    Shipping findById(@PathVariable(name="id") Integer id);
}

@RequestMapping注解里面没有加backend-shipping
找到问题就好解决了,这里主要有两种方式:
方式一:在@RequestMapping注解里加,可以这样写:

@RequestMapping("backend-shipping/shipping/")

方式二:在@FeignClient注解里加上一个path路径的配置,如下:

@FeignClient(value = "backend-shipping", path = "/backend-shipping")

加上之后再访问项目就没问题了!!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值