【轉 :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問題解決!