Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'com.youzi.client.AdsServiceClient' method
com.youzi.client.AdsServiceClient#listById(String)
to {GET /ads-api/listById/{id}}: There is already 'guanggaoServiceimpl' bean method
com.youzi.service.impl.GuanggaoServiceimpl#listById(String) mapped.
AdsServiceClient extends GuanggaoService
前者继承了后者的所有方法,微服务接口就不要这样扩展了
用的是Feign做RPC接口调用,你这样继承接口,会被动态代理创建两个实例,且具有想同的请求URI,所以创建第子接口的代理实现类就会出错
不知道你这个问题是否已经解决, 如果还没有解决的话:根据错误信息提示,在AdsServiceClient中缺少listById方法。需要检查Springboot应用中是否引用了AdsServiceClient类,并且该类中是否定义了listById方法。如果确实没有listById方法,需要添加该方法并进行相关实现。
如果AdsServiceClient中已经定义了listById方法,而仍然出现错误,那么可能是因为RequestMappingHandlerMapping存在重复的method mapping映射。需要手动指定method mapping,以解决重复的问题。
具体操作如下: 1.在对应的Controller方法上加上@RequestMapping注解,指定method属性为具体的请求方法,例如GET或POST。 2.使用uniqueRequestMappingName属性设置RequestMapping的唯一名称。 3.在对应的RequestMappingHandlerMapping实现类中,使用RequestMappingInfoHandlerMapping的getHandlerMethodsForMappingName()方法,指定mapping name,获取特定RequestMapping的HandlerMethod。
参考代码如下:
// Controller中指定method和uniqueRequestMappingName
@RequestMapping(value = "/your/path", method = RequestMethod.GET, uniqueRequestMappingName = "your_unique_mapping_name")
public String yourControllerMethod() {
// your function
}
// 在RequestMappingHandlerMapping实现类中获取特定RequestMapping的HandlerMethod
HandlerMethod handlerMethod = requestMappingHandlerMapping.getHandlerMethodsForMappingName("your_unique_mapping_name").get(RequestMethod.GET);