完整信息:
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘com.liqiang.hrm.client.CourseClient’ method
public abstract com.liqiang.hrm.util.AjaxResult com.liqiang.hrm.client.CourseClient.save(com.liqiang.hrm.domain.Course)
to {[/course/save],methods=[POST]}: There is already ‘courseController’ bean method
public com.liqiang.hrm.util.AjaxResult com.liqiang.hrm.web.controller.CourseController.save(com.liqiang.hrm.domain.Course) mapped.
这个是在使用Spring Cloud微服务项目时,内部调用使用Feign时,启动项目出现的异常。
意思说我 Controller这一个控制层请求映射了两个方法,且在Controller中重复了,所以报错。 或者说,如果一个项目中有两个@RequestMapping("/xxx")完全相同就会报 java.lang.IllegalStateException.
于是去对比我的代码,发现所有的Client接口在对Controller托底时,使用了与Controller一致的@RequestMapping("/course"),如图示,接着把所有的XxxClient里的所有@RequestMapping("/course")都改掉,重启项目。成功运行。
那么问题来了,既然是对Controller托底,那么RequestMapping不该一致才对吗? ,如果不一致又如何实现对自己服务托底的呢,如果必须一致又该用什么方式来规避这个异常呢,求解。