non-compatible bean definition of same name and class [jx.tour.service.BackCheckServiceImp]

导入一个从网上下载的项目,在开启tomcat时,出现了下方的报错

Unexpected exception parsing XML document from file [E:\li_eclipse\graduated\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\tour\WEB-INF\classes\spring\applicationContext-service.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'backCheckServiceImp' for bean class [jx.tour.service.impl.BackCheckServiceImp] conflicts with existing, non-compatible bean definition of same name and class [jx.tour.service.BackCheckServiceImp]

其中non-compatible bean definition of same name and class [jx.tour.service.BackCheckServiceImp]
的有道翻译为
相同名称和类的不兼容bean定义[jx.tour.service.BackCheckServiceImp]
也就是说,有spring在生成bean时出现了两个BackCheckServiceImp
也即是说,spring找到 有相同的实现类名在不同的package目录下

经过调查发现,在service包与serviceImpl包下同时出现了BackCheckServiceImp,删掉一个即可

删除时注意,最好在磁盘里进行删除而不是在eclipse进行删除,不然容易删除不干净
删除之后重新clean一下再进行发布

在搜索过程中我发现了另一个解决办法,主要用于不同的模块出现了相同的类的情况

可以使用@Controller来实现相同名字的类具有不同的bean的id的效果

即:

@Controller("testbillsave")
@RequestMapping("/billsave")
public class BillSaveController {

    @RequestMapping("/dosave")
    public String saveBill(){

        return "billsave";
    }

}

以及

@Controller("realbillsave")
@RequestMapping("/billsave_test")
public class BillSaveController {

    @RequestMapping("/test")
    public String test(){
        return "test";
    }

}

原文章地址:SpringMVC conflicts with existing, non-compatible bean definition of same name and class 的解决办法

猜你喜欢

转载自blog.csdn.net/weixin_44538032/article/details/89957030