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<Dep> 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<Dep> 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<Dep> 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接口一致。
|