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

Ambiguous mapping found. Cannot map 'xxxxController' bean method

时间: 2024-10-09 22:17:10

Ambiguous mapping found. Cannot map 'xxxxController' bean method的相关文章

Ambiguous mapping found. Cannot map 'competeController' bean method

报错: 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 'comp

java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'XXXXX' bean

今天启动srpingmvc项目的时候出现了这个异常, 原因: 在同个项目中,我复制了其中一个 Controller 作为备份 却忘记修改  @RequestMapping("/xxx") 在springmvc中不能同时映射一个名字(@RequestMapping("/xxx") java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'XXXXX' bean

Spring异常Ambiguous mapping found.

SpringMVC启动时不停重复加载bean 通过浏览器访问获取异常: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

Caused by: java.lang.IllegalStateException: Ambiguous mapping found

Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map ‘myCockpitMgrController’ bean method 报错为:Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map ‘myCockpitMgrController’ bean method 是因为两个请求,请求到同

java Map与Bean相互转化

import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap;

Map和Bean的相互转换

BeanUtils位于org.apache.commons.beanutils.BeanUtils下面,其方法populate的作用解释如下: 完整方法: BeanUtils.populate( Object bean, Map properties ), 这个方法会遍历map<key, value>中的key,如果bean中有这个属性,就把这个key对应的value值赋给bean的属性. 1.bean 转换成 map Person person1=new Person(); person1.

Java Map和Bean之前的转换

// Map --> Bean 2: 利用org.apache.commons.beanutils 工具类实现 Map --> Bean       public static void transMap2Bean2(Map<String, Object> map, Object obj) {           if (map == null || obj == null) {               return;           }           try {  

Ambiguous mapping found

If you have a single default method (without explicit path mapping), then all requests without a more specific mapped method found will be dispatched to it. If you have multiple such default methods, then the method name will be taken into account fo

Map转Bean小工具

public static <T> T converter(Map<String, Object> map, Class<T> clz) { T obj = null; try { obj = clz.newInstance(); BeanInfo beanInfo = Introspector.getBeanInfo(clz); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescrip