Ambiguous mapping. Cannot map ‘xxx‘ method 启动异常解决

问题描述

问题代码展示:

@SpringBootApplication
@ComponentScan(nameGenerator = QueryAllCityAnnotationBeanNameGenerator.class)
public class Main {
   
   
    public static void main(String[] args) {
   
   
        SpringApplication.run(Main.class, args);
    }
`Ambiguous mapping. Cannot map 'chaugnyezhezhuceController' method` 错误通常是因为存在两个方法具有相同的映射路径和 HTTP 方法,在 Spring 尝试创建 `requestMappingHandlerMapping Bean` 时引发了冲突 [^4]。以下是一些可能的解决方法: ### 检查映射路径 确保 `chaugnyezhezhuceController` 类中没有两个方法使用了相同的 `@RequestMapping`、`@GetMapping`、`@PostMapping` 等注解,且路径和 HTTP 方法一致。例如: ```java @RestController public class ChaugnyezhezhuceController { // 错误示例,两个方法映射路径和 HTTP 方法相同 @GetMapping("/test") public String test1() { return "Test 1"; } @GetMapping("/test") public String test2() { return "Test 2"; } } ``` 要修改为不同的路径: ```java @RestController public class ChaugnyezhezhuceController { @GetMapping("/test1") public String test1() { return "Test 1"; } @GetMapping("/test2") public String test2() { return "Test 2"; } } ``` ### 检查不同控制器中的映射 除了当前控制器,还要检查其他控制器中是否有相同的映射路径。比如,可能有另一个控制器也有 `/test` 这个映射路径。 ### 检查全局配置 有时候,全局的配置文件或者自动配置可能会导致映射冲突。检查 `application.properties` 或 `application.yml` 中的配置,确保没有重复的配置影响了映射。 ### 检查继承关系 如果 `chaugnyezhezhuceController` 有继承关系,要检查父类中是否存在相同的映射路径。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿进阶

千言万语都不及一句“谢谢”

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值