Ambiguous mapping found. Cannot map ' Xxxxcontroller ' Bean method

Source: Internet
Author: User

1. Background

To do a demo today, clone a SPRINGMVC MyBatis project from GitHub (Https://github.com/komamitsu/Spring-MVC-sample-using-iBatis)

Start error after package into war:

Org.springframework.beans.factory.BeanCreationException:Error creating bean with Name ' Org.springframework.web.servlet.mvc.method.annotation.requestmappinghandlermapping#0 ': Initialization of beans Failed Nested exception is java.lang.IllegalStateException:Ambiguous mapping found. Cannot map ' Personlistcontroller 'Bean Method Publicjava.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 Publicjava.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. Analysis of the situation

The above situation

1. Reason 1:bean repeated initialization: initialized once with @controller annotations, defined once in ApplicationContext

By searching the original works, it is found that there is no duplicate initialization.

2. Duplicate mappings defined in different controllers.

Focus on finding the error Personlistcontroller and PersonController find the map are consistent, found the problem lies.

3. Problem solving

Comment out one of the @controller

4. Verifying the problem

Ok

Ambiguous mapping found. Cannot map ' Xxxxcontroller ' Bean method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.