• Ambiguous mapping found. Cannot map 'xxxxController' bean method


    1.背景

    今天要做一个demo,从github上clone一个springmvc mybatis的工程(https://github.com/komamitsu/Spring-MVC-sample-using-iBatis)

    打包成war后启动报错:

    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 'personListController' bean method 
    public java.lang.String com.komamitsu.addressbook.controller.PersonListController.create(com.komamitsu.addressbook.domain.Person,org.springframework.validation.BindingResult)
    to {[/person/create],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'personController' bean method
    public java.lang.String com.komamitsu.addressbook.controller.PersonController.create(com.komamitsu.addressbook.domain.Person,org.springframework.validation.BindingResult) mapped.
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
        at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
        at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
        at javax.servlet.GenericServlet.init(GenericServlet.java:158)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4901)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5188)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'personListController' bean method

    2. 分析情况

        上述情况

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

             通过对工程原文查找,发现没有重复初始化的情况。

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

        重点查找了报错的personListController和personController 发现映射都一致,发现问题所在。

    3. 解决问题

       注释掉其中一个@Controller即可

    4. 验证问题

        ok 

              

  • 相关阅读:
    20165336 2017-2018-2《Java程序设计》课程总结
    2017-2018-2 20165336 实验五《网络编程与安全》实验报告
    2017-2018-2 20165336 实验四《Android开发基础》实验报告
    2018-2019-1 20165314 《信息安全系统设计基础》第四周学习总结
    2018-2019-1 20165314 《信息安全系统设计基础》第三周学习总结
    2018-2019-1 20165314《信息安全系统设计基础》实验一 缓冲区溢出漏洞实验
    20165314 [第二届构建之法论坛] 预培训心得(Java版)
    20165314 2017-2018-2《Java程序设计》课程总结
    20165314实验五《网络编程与安全》实验报告
    20165314实验四
  • 原文地址:https://www.cnblogs.com/davidwang456/p/4387654.html
Copyright © 2020-2023  润新知