2010-08-13 149 views
0

我正在運行我的JunitTest,它給出了以下錯誤..不是失敗。JUnit TestCase失敗

 
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文件,我無法找到問題的所在。任何想法?

回答

0

爲了進一步幫助您,我們可能需要查看單元測試代碼並知道您使用的彈簧版本。
我的初始問題是,您沒有用@ContextConfiguration註釋表示配置文件的位置。

0

看起來像你的一個域類的映射不正確。您是使用基於XML還是基於註釋的配置?

0

類dfi.fin.dcm.syn.loantrading.model.engine.result.BDTSTest不存在的persistence.xml 文件是否使用persistence.xml中<exclude-unlisted-classes>false</exclude-unlisted-classes>? 如果是這種情況,您需要手動映射所有實體類。