使用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")

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

你可能感兴趣的:(#,SpringCloud,错误记录,spring,cloud)