JUnit TestCase失败

时间:2010-08-13 07:04:53

标签: java hibernate spring junit

我正在运行我的JunitTest,它会出现以下错误..而不是失败。

 Error creating bean with name 'reportDAO' defined in class path resource [LT.xml]:
 Cannot resolve reference to bean 'hibernateTemplate' while setting bean property 'hibernateTemplate';
 nested exception is org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'hibernateTemplate' defined in class path resource [LT.xml]: 
 Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; 
 nested exception is org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'sessionFactory' defined in class path resource [LT.xml]: 
 Invocation of init method failed; nested exception is org.hibernate.MappingException: 
 Association references unmapped class: dfi.fin.dcm.syn.loantrading.model.engine.result.BDTSTest
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1210)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:978)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:462)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:404)
 at java.security.AccessController.doPrivileged(Native Method)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:375)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:263)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:170)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:260)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:184)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:430)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
 at org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:199)
 at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:179)
 at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:158)
 at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)
 at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:87)
 at junit.framework.TestCase.runBare(TestCase.java:128)
 at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:120)
 at junit.framework.TestSuite.runTest(TestSuite.java:230)
 at junit.framework.TestSuite.run(TestSuite.java:225)
 at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

我检查了我各自的xml文件,这些xml文件中都存在所有引用,我找不到问题所在。有什么想法吗?

3 个答案:

答案 0 :(得分:0)

为了进一步帮助您,我们可能需要查看单元测试代码并知道您正在使用的弹簧版本。
我最初的问题是,您没有使用指示配置文件位置@ContextConfiguration 注释。

答案 1 :(得分:0)

看起来您的某个域类的映射不正确。您使用的是基于XML还是基于注释的配置?

答案 2 :(得分:0)

类dfi.fin.dcm.syn.loantrading.model.engine.result.BDTSTest不存在文件persistence.xml 你在persistence.xml中使用<exclude-unlisted-classes>false</exclude-unlisted-classes>吗? 如果是这种情况,您需要手动映射所有实体类。