使用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"}]

The reason for the error is because: the interface of Feign does not correspond to the interface of the service 

The Api layer interface is like this

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

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

    @RequestMapping("/dep/get")
    List<Dep> queryAllDep();

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

Feign layer interface is like this

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

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

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

The service layer interface must correspond to it to be accessed  

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

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

I reported an error because the service layer interface did not correspond to the Feign layer interface. Make sure that the url interface of the API layer and the Service layer are consistent, otherwise an error will appear.

 The project structure is shown in the figure: The general process of calling is: the client calls the API layer, and the API layer calls the service layer.

It is necessary to ensure that the url interfaces of the API layer and the service layer are consistent.

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/122910656