• SpringMVC“Ambiguous mapping found. Cannot map 'XXXController' bean method”解决方法


    【转 :http://www.fanfanyu.cn/news/staticpagefile/2351.html】 

    最近在开发项目的过程中SpringMVC抛了个“Ambiguous mapping found. Cannot map 'clientPoolController' bean method”异常出来,如下(只列出重要的部分,以免篇幅过长):

       org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'clientPoolController' bean method

       ......

       at java.lang.Thread.run(Thread.java:745)

       Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'clientPoolController' bean method

       根据上述异常情况,分析得出一下结论:

        1. bean重复初始化:使用@controller注解初始化一次,在applicationContext中又定义一次。

         注:我通过对项目对应配置文件查找,发现并没有重复初始化的情况。

        2. 在不同的Controller中定义的映射重复。

         注:项目中clientPoolController与clientController是继承关系,clientPoolController继承clientController。所以重点查找了报错的clientPoolController和clientController发现映射都一致,发现问题所在。

       解决方案:

        注释掉clientPoolController中的@Controller标签即可。

       运行测试成功,OK问题解决!

        3. 2018-11-09更新:路径中的RequestMapping中含有小数点这个不被允许。

       解决方案:

        去掉小数点作为@RequestMapping路径的问题,本次tomcat使用的NIO模式JDK7,tomcat7环境,同事修改成了带版本号的访问路径,导致了本次的问题比如:。

    ```java @RequestMapping("/gateway_2.0") ``` 改为 ```java @RequestMapping("/gateway_2") ``` 即可得到解决
  • 相关阅读:
    CentOS 7 安装MySQL 5.7
    Introduction to BGP (4)
    Introduction to BGP (3)
    Introduction to BGP (2)
    Introduction to BGP (1)
    Cisco NAT Fundation
    Linux安装Nginx
    GRE协议学习与练习
    Oracle Study Note : Users and Basic Security
    Oracle Study Note : Tablespace and Data Files
  • 原文地址:https://www.cnblogs.com/jpfss/p/9933398.html
Copyright © 2020-2023  润新知