conflicts with existing, non-compatible bean definition of same name and cla

SpringMVC conflicts with existing, non-compatible bean definition of same name and class 的解决办法,springmvc获取bean

SpringMVC的Controller 应该是采用类似键值对(key/value)的映射方式处理的。而当中的键,默认是用cotroller的类名(非全类名)作为键。这样,如果不同包下面的两个Contoller 重名的话,就会导致SpringMVC的容器管理中的controller map中的key重复了。

解决这个问题也比较简单。

在@Controller 中,使用重名名类名就可以了或者 @Controller("testcontroller")这样命名

因为如果在使用注解 @Controller 时候,如果不使用命名,而SpringMVC会默认把类名的头一个字母小写,然后放到一个map中。

 尽管上面两个类全类名不同,但是他们使用了@Controller 注解的时候,都没有使用命名。在SpringMVC在扫描Controller的时候, , 放到一个全局的map中。

这样,就会出现两个键完全一样的Controller。由于SpringMVC不使用覆盖的方式处理具有相同键的不同全类名的Controller,、扫描的时候就会包上面的错误。

还有一种情况是:target文件夹里用重名的.class文件