Feign调用异常FeignException$NotFound: [404] during

Feign调用异常FeignException$NotFound: [404] during

1. 问题描述

遇到的问题中很大一部分其实都不是大问题,之所以当时觉得难,要么是基础知识不牢,另一个就是细节。

1.1 问题环境

Springboot项目两个:
category项目:端口8080
weimob项目:端口8081
weimob通过FeignClient调用category项目。

  1. category项目
/**
 * (Category)控制层
 *
 * @author makejava
 * @since 2021-06-03 07:20:41
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    /**
     * 测试服务
     */
    @GetMapping("/test")
    public Response test() {
        return Response.createSuccessResponse("查询成功", "我是测试服务");
    }
}

  1. weimob项目
/**
 * 测试
 * @author zrj
 * @since 2021-07-25
 */
@RestController
@RequestMapping("/weimob")
public class ActivityController {
    @Resource
    private CategoryService categoryService;
    @GetMapping("/test")
    @ApiOperation(value = "微盟获取Code")
    public Response test() throws URISyntaxException {
        System.out.println("-----测试-----");
        URI uri = new URI("http://localhost:8080/category/test");
        Response response = categoryService.test(uri);
        return Response.createSuccessResponse("查询成功", response);
    }
}

/**
 * 测试接口Openfeign
 * @author zrj
 * @since 2021/7/25
 **/
@Service("WeimobAuthorize")
@FeignClient(url = "http://localhost:8080/category", name = "CategoryService")
public interface CategoryService {
    @GetMapping("/test")
    Response test(URI uri);
}

1.2 异常信息

feign.FeignException$NotFound: [404] during [GET] to [http://localhost:8080/category/test/test] 

2. 问题分析

FeignException$NotFound: [404] during [GET] to [http://localhost:8080/category/test/test]
网上有很多,比如feign接口没有注入,又是没写RestController,或者@Request注解没写等等。

FeignException,肯定是调用异常,首先测试服务项目,调用正常,说明是客户端问题。
[404],肯定是客户端调用问题,没有调用到,首先检查地址端口,FeignClient注册,依赖等等。

通过日志打印发现是路径问题,多了个test,[http://localhost:8080/category/test/test] 。

URI uri = new URI(“http://localhost:8080/category/test”);
Response response = categoryService.test(uri);
这里的URI只是替换了service类注解上的url,
@FeignClient(url = “http://localhost:8080/category”, name = “CategoryService”)
对于方法上的 @GetMapping("/test")还会在拼接上去,这个很多时候容易忽略,特此记录。

3.解决方案

去掉客户端接口方法上的 @GetMapping("/test"),改为@GetMapping即可。

  • 17
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值