springboot由于controller重复方法出现以下错误

本文详细解析了在SpringBoot项目中遇到的启动失败问题,具体表现为因控制器方法映射冲突导致的Bean创建异常。通过调整@RequestMapping注解的值和方法名称,成功解决了问题并恢复正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2020-01-28 11:25:13.592 ERROR[main]org.springframework.boot.SpringApplication.reportFailure:845 -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 ‘contractHumanController’ method
public com.xtj.utils.Result<java.lang.Object> com.xtj.controller.ContractHumanController.update(com.xtj.pojo.ContractHuman)
to {[/contracthuman/update],methods=[POST]}: There is already ‘contractHumanController’ bean method

从提示信息中可以看出是controller层中的错误,但是翻译错误后又看不出是什么错误,就是说某个bean不能被注入啥了,仔细的检查了一下controller层后发现错误原因
在这里插入图片描述
在复制的过程中不小心写了2个相同的名字的controller方法,但是由于修改了传入参数,它还不报错,难受啊,只要将requestMapping中的值和方法名更换了,重启之后正常运行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值