试图为dao hibernate运行Junit测试会给我以下错误

时间:2012-02-20 20:03:36

标签: java hibernate spring junit

错误消息为: - Error creating bean with name 'agencyDetailsInterfaceService' defined in class path resource

下面的堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'agencyDetailsInterfaceService' defined in class path resource [spring/aas-service.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy51 implementing com.qbe.us.aas.service.IAgencyBatchOutService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.qbe.us.aas.service.impl.AgencyBatchOutService' for property 'agencyBatchOutService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy51 implementing com.qbe.us.aas.service.IAgencyBatchOutService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.qbe.us.aas.service.impl.AgencyBatchOutService] for property 'agencyBatchOutService': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    at com.qbe.us.aas.dao.hibernate.AccountDecPrintHibernateDaoJunitTest.setUp(AccountDecPrintHibernateDaoJunitTest.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    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)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy51 implementing com.qbe.us.aas.service.IAgencyBatchOutService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.qbe.us.aas.service.impl.AgencyBatchOutService' for property 'agencyBatchOutService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy51 implementing com.qbe.us.aas.service.IAgencyBatchOutService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.qbe.us.aas.service.impl.AgencyBatchOutService] for property 'agencyBatchOutService': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:462)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    ... 35 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [$Proxy51 implementing com.qbe.us.aas.service.IAgencyBatchOutService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.qbe.us.aas.service.impl.AgencyBatchOutService] for property 'agencyBatchOutService': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:447)
    ... 41 more

1 个答案:

答案 0 :(得分:1)

可能是您将属性agencyBatchOutService声明为实现类型而不是接口IAgencyBatchOutService?。

如果您需要使用该实现,请使用<aop:config proxy-target-class="true">强制Spring使用cglib代理。