关于SpringBoot 启动失败 Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. 的问题解析

发布时间 2023-09-08 14:21:57作者: 王半仙儿的博客
Application run failed
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 'toCCustomerController' method 

 

  出现此情况的 ,仔细观察当前controller 中的 requestMapping 中 是否存在相同url ,比如说不同方法名的请求路径相同

 

eg:

@PostMapping("/woxihuandabaitui")
public Object A(){

return "";

}

@PostMapping("/woxihuandabaitui")
public Object B(){

return "";

}

  

woxihuandabaitui 就是原因,Spring不允许映射中存在摸棱两可的requestMapping。改个名就好了,实际中也不可能存在一个类中俩一样的requestMapping,

如果有,那就是你new  bee