caused by:org.springframework.beans.factory.BeanCreationException:Could not autowire field

Source: Internet
Author: User

1 Error description

Org.springframework.beans.factory.BeanCreationException:Error creating bean with Name ' Com.sc.oa.test.timer.dao.TimerDaoTest ': Injection of autowired dependencies failed; Nested exception is org.springframework.beans.factory.BeanCreationException:Could not Autowire field:private Com.sc.oa.timer.dao.TimerDao Com.sc.oa.test.timer.dao.TimerDaoTest.timerDao; Nested exception is Org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [ Com.sc.oa.timer.dao.TimerDao] found for dependency:expected at least 1 beans which qualifies as Autowire candidate for Thi s dependency. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (required=true)}at Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ( autowiredannotationbeanpostprocessor.java:292) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean ( abstractautowirecapablebeanfactory.java:1185)At Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties ( abstractautowirecapablebeanfactory.java:384) at Org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies ( DEPENDENCYINJECTIONTESTEXECUTIONLISTENER.JAVA:110) at Org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance ( DEPENDENCYINJECTIONTESTEXECUTIONLISTENER.JAVA:75) at Org.springframework.test.context.TestContextManager.prepareTestInstance (testcontextmanager.java:331) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest (springjunit4classrunner.java:213) at Org.springframework.test.context.junit4.springjunit4classrunner$1.runreflectivecall ( springjunit4classrunner.java:290) at Org.junit.internal.runners.model.ReflectiveCallable.run ( REFLECTIVECALLABLE.JAVA:12) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock ( springjunit4classrunner.java:292) at org.springFramework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:233) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:87) at Org.junit.runners.parentrunner$3.run (parentrunner.java:238) at Org.junit.runners.parentrunner$1.schedule ( parentrunner.java:63) at Org.junit.runners.ParentRunner.runChildren (parentrunner.java:236) at org.junit.runners.parentrunner.access$000 (parentrunner.java:53) at Org.junit.runners.parentrunner$2.evaluate ( parentrunner.java:229) at Org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate ( RUNBEFORETESTCLASSCALLBACKS.JAVA:61) at Org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate ( runaftertestclasscallbacks.java:71) at Org.junit.runners.ParentRunner.run (parentrunner.java:309) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run (springjunit4classrunner.java:176) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TesTreference.run (junit4testreference.java:50) at Org.eclipse.jdt.internal.junit.runner.TestExecution.run ( testexecution.java:38) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (Remotetestrunner.java : 459) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:675) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (remotetestrunner.java:382) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (remotetestrunner.java:192) caused by: Org.springframework.beans.factory.BeanCreationException:Could not Autowire field:private Com.sc.oa.timer.dao.TimerDao Com.sc.oa.test.timer.dao.TimerDaoTest.timerDao; Nested exception is Org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [ Com.sc.oa.timer.dao.TimerDao] found for dependency:expected at least 1 beans which qualifies as Autowire candidate for Thi s dependency. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (requIred=true)}at org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$ Autowiredfieldelement.inject (autowiredannotationbeanpostprocessor.java:508) at Org.springframework.beans.factory.annotation.InjectionMetadata.inject (injectionmetadata.java:87) at Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ( autowiredannotationbeanpostprocessor.java:289) ... morecaused by:org.springframework.beans.factory.NoSuchBeanDefinitionException:No Qualifying Bean of type [ Com.sc.oa.timer.dao.TimerDao] found for dependency:expected at least 1 beans which qualifies as Autowire candidate for Thi s dependency. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (required=true)}at Org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException ( defaultlistablebeanfactory.java:1103) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDEpendency (defaultlistablebeanfactory.java:963) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency ( defaultlistablebeanfactory.java:858) at Org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject (autowiredannotationbeanpostprocessor.java:480) ... More

2 Error Reason

Analysis of the information printed by the console that the JUnit unit test, only the DAO interface, did not write its implementation, the test will invoke the DAO interface method, and to implement it, but there is a lack of interface implementation, that is, the query method (data processing part)


3 Solutions

Create DAO implementations, implement their own interfaces, query methods

caused by:org.springframework.beans.factory.BeanCreationException:Could not autowire field

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.