栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

使用Feign 报404feign.FeignException$NotFound: [404] during [GET] to [http://SPRINGCLOUD-DEP-PROVIDER/de

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Feign 报404feign.FeignException$NotFound: [404] during [GET] to [http://SPRINGCLOUD-DEP-PROVIDER/de

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Feb 13 16:33:34 CST 2022
There was an unexpected error (type=Internal Server Error, status=500).
[404] during [GET] to [http://SPRINGCLOUD-DEP-PROVIDER/dep/get/8] [DeptService#queryDepById(int)]: [{"timestamp":"2022-02-13T08:33:34.858+00:00","status":404,"error":"Not Found","message":"No message available","path":"/dep/get/8"}]
feign.FeignException$NotFound: [404] during [GET] to [http://SPRINGCLOUD-DEP-PROVIDER/dep/get/8] [DeptService#queryDepById(int)]: [{"timestamp":"2022-02-13T08:33:34.858+00:00","status":404,"error":"Not Found","message":"No message available","path":"/dep/get/8"}]

引起错误的原因就是因为 :Feign的接口 和服务的接口不对应导致的 

Api层接口是这样的

@Component
@FeignClient(value = "SPRINGCLOUD-DEP-PROVIDER")
public interface DeptService {

    @RequestMapping("/dep/del/{id}")
    int deleteDep(@PathVariable(name = "id") int id);

    @RequestMapping("/dep/get")
    List queryAllDep();

    @RequestMapping("/dep/get/{id}")
    Dep queryDepById(@PathVariable(name = "id") int id);
}

Feign层接口是这样的

 @RequestMapping("/custom/dep/get/{id}")
    public Dep getDepById(@PathVariable("id") int id){
        return this.deptService.queryDepById(id);
    }

    @RequestMapping("/custom/dep/get")
    public List getDep(){
        return this.deptService.queryAllDep();
    }

    @RequestMapping("/custom/dep/del/{id}")
    public int delDep(@PathVariable("id") int id){
        return this.deptService.deleteDep(id);
    }

服务层接口必须与其对应才能访问到  

@GetMapping("/dep/get")
    public List getAllDep(){
        return depService.queryAllDep();
    }

    @GetMapping("/dep/get/{id}")
    public Dep getDep(@PathVariable("id") int id){
        return depService.queryDepById(id);
    }

我是因为服务层接口与Feign层接口不对应导致了报错,要确保 API层和Service层的url接口一致,不然就会出现报错。

 项目结构如图: 调用的大致流程是:客户端调用API层,API层再去调用服务层,

需要确保API层和服务层的url接口一致。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/735971.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号