SpringBoot项目启动失败,Ambiguous mapping. Cannot map ‘xxxController‘ method

2023-05-16

目录

 

项目场景:

问题描述:

原因分析:

解决方案:


项目场景:

SpringBoot 2.1.15.RELEASE


问题描述:

SpringBoot项目启动失败了,后台日志没有Error的异常堆栈信息。详细查看了日志后,发现有WARN级别的信息:

[main] WARN  org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/D:/tfb-work/maven-repositories/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/D:/tfb-work/maven-repositories/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is 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 'xxxController' method 
public com.xxx.framework.web.controller.ResponseDto<> com.controller.XxxController.workListStatistics()
to {[/xxx/workListStatistics],methods=[POST],produces=[application/json;charset=UTF-8]}: There is already 'yyyController' bean method
public com.framework.web.controller.ResponseDto<> com.controller.yyy.YyyController.workListStatistics() mapped.

 

原因分析:

分析上面的错误信息, Ambiguous mapping. Cannot map 'xxxController' method ,意思是模糊的方法/路径匹配,XxxController.workListStatistics()这个方法和YyyController.workListStatistics()的方法都配置了一样的访问路径

查看了下这两个方法的访问路径注解,果然是一样的。


解决方案:

按实际情况处理,如我这边是修改两个Controller的基础访问路径。

注:原开发者设置了同一个路径,是因为这两个Controller不在同一个jar包里,本意是不允许相互依赖,可是没有提前声明。优化后,更改了这两个Controller的基础访问路径。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SpringBoot项目启动失败,Ambiguous mapping. Cannot map ‘xxxController‘ method 的相关文章

随机推荐