欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ambiguous mapping found. Cannot map 'xxxController' bean method

程序员文章站 2022-07-15 11:43:56
...

错误信息如下:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'declareMattersController' bean method 
public java.lang.String com.jeeplus.modules.declare.web.DeclareMattersController.form2(com.jeeplus.modules.declare.entity.DeclareMatters,org.springframework.ui.Model)
to {[/a/declare/declareMatters/form2],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'declareMattersController' bean method
public java.lang.String com.jeeplus.modules.declare.web.DeclareMattersController.form2(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.springframework.ui.Model,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,freemarker.template.TemplateException,java.lang.IllegalArgumentException,java.lang.IllegalAccessException mapped.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at com.jeeplus.modules.sys.listener.WebContextListener.initWebApplicationContext(WebContextListener.java:16)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

 遇到错误不要慌,耐心查看报错信息。解决问题一般分三个步骤:

1、确定大概方向(一般的错误提示重点会在上面,所以从上往下开始查看。)

发现重点“Ambiguous mapping found. Cannot map 'declareMattersController' bean method ”,大致意思是“模糊映射发现。不能映射'declareMattersController' bean方法”   。映射:只能是一对一映射或多对一映射。此处的关键提示是“映射模糊”,那必定是映射关系不正确,确定大概方向

2、根据关联信息,发现问题根本

再往下看看还有没有与此关联的错误信息,发现重点“public java.lang.String com.jeeplus.modules.declare.web.DeclareMattersController.form2(com.jeeplus.modules.declare.entity.DeclareMatters,org.springframework.ui.Model)
to {[/a/declare/declareMatters/form2],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'declareMattersController' bean method”,由此可知“form2”方法在“declareMattersController”中已经存在,结合刚刚的方向得知,一个“declareMattersController”中出现了2个“form2”方法,是一对多的关系,这在映射中是不合法的,故出现“映射模糊”的错误。通过分析错误信息得出,出现问题的原因是方法名字重复,这就是问题的根本。

3、解决错误

解决办法:对重复的方法进行重命名,改变其中任一方法名即可。

PS:重点,可以理解为你能看懂或者熟悉的代码。

相关标签: java异常