ZPY博客

SpringBoot conflicts with existing, non-compatible bean definition of same name and class 的解决办法

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'formatController' for bean class [jp.co.jet.mst_format_setting_order.controllers.FormatController] conflicts with existing, non-compatible bean definition of same name and class [jp.co.jet.format_setting_order.controllers.FormatController]

根据控制台的错误信息,不难发现是由于两个controller重名了导致tomcat启动失败。

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

解决方法:

除了改成两个不同的controller名外,也可以在@Controller注解里加上名称

@Controller("format1")
public class FormatController