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

时间:2021-11-23 17:04:23
spring的测试包 spring-test.jar JUnit4.5 

请教大侠们,如何解决以下问题?

项目中用注解,省用了*.hbm.xml和在spring配置文件里定义一大堆的bean


org.springframework.beans.factory.BeanDefinitionSt oreException: Unexpected exception parsing XML document from URL [file:/work/forjarproj/web/WEB-INF/classes/spring/dispatch-servlet.xml]; nested exception is java.lang.IllegalStateException: Annotation-specified bean name 'baseControler' for bean class [com.forjarproj.controller.BaseControler] conflicts with existing, non-compatible bean definition of same name and class [com.forjarproj.controller.BaseControler]
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:420)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:310)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:143)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:178)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:149)
at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:212)
at org.springframework.test.AbstractSingleSpringConte xtTests.createApplicationContext(AbstractSingleSpr ingContextTests.java:242)
at org.springframework.test.AbstractSingleSpringConte xtTests.loadContextLocations(AbstractSingleSpringC ontextTests.java:212)
at org.springframework.test.AbstractSingleSpringConte xtTests.loadContext(AbstractSingleSpringContextTes ts.java:187)
at org.springframework.test.AbstractSpringContextTest s.getContext(AbstractSpringContextTests.java:140)
at org.springframework.test.AbstractSingleSpringConte xtTests.setUp(AbstractSingleSpringContextTests.jav a:100)
at junit.framework.TestCase.runBare(TestCase.java:132 )
at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:76)
at junit.framework.TestResult$1.protect(TestResult.ja va:110)
at junit.framework.TestResult.runProtected(TestResult .java:128)
at junit.framework.TestResult.run(TestResult.java:113 )
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:2 32)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run( JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
Caused by: java.lang.IllegalStateException: Annotation-specified bean name 'baseControler' for bean class [cn.shell.controller.BaseControler] conflicts with existing, non-compatible bean definition of same name and class [cn.shell.controller.BaseControler]
at org.springframework.context.annotation.ClassPathBe anDefinitionScanner.checkCandidate(ClassPathBeanDe finitionScanner.java:267)
at org.springframework.context.annotation.ClassPathBe anDefinitionScanner.doScan(ClassPathBeanDefinition Scanner.java:208)
at org.springframework.context.annotation.ComponentSc anBeanDefinitionParser.parse(ComponentScanBeanDefi nitionParser.java:85)
at org.springframework.beans.factory.xml.NamespaceHan dlerSupport.parse(NamespaceHandlerSupport.java:69)
at org.springframework.beans.factory.xml.BeanDefiniti onParserDelegate.parseCustomElement(BeanDefinition ParserDelegate.java:1255)
at org.springframework.beans.factory.xml.BeanDefiniti onParserDelegate.parseCustomElement(BeanDefinition ParserDelegate.java:1245)
at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.parseBeanDefinitions(Defau ltBeanDefinitionDocumentReader.java:135)
at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.registerBeanDefinitions(De faultBeanDefinitionDocumentReader.java:92)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.registerBeanDefinitions(XmlBeanDefinit ionReader.java:507)
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:398)
... 26 more 

3 个解决方案

#1


是不是类名称冲突

#2


现在整体项目能跑起来,没有任何冲突,

但是我对spring进行测试,就出这些错,整体工程用的注解太多了,

哪位熟悉注解的,有没有出现过类似的问题?

求解,谢谢

#3


没有人知道怎么测试吗

#1


是不是类名称冲突

#2


现在整体项目能跑起来,没有任何冲突,

但是我对spring进行测试,就出这些错,整体工程用的注解太多了,

哪位熟悉注解的,有没有出现过类似的问题?

求解,谢谢

#3


没有人知道怎么测试吗