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

本文档记录了一个SpringBoot项目在2.1.15.RELEASE版本中启动失败的问题。问题源于两个Controller中存在相同访问路径的工作方法,导致Ambiguous mapping异常。解决方案是修改Controller的基础访问路径,确保方法映射的唯一性,从而成功启动项目。
摘要由CSDN通过智能技术生成

目录

 

项目场景:

问题描述:

原因分析:

解决方案:


项目场景:

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的基础访问路径。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值