一、前言
关于在使用mybatis的xml映射实体dao实例化的时报“org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDivideService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xwood.pms.dao.myDivideDAO com.xwood.pms.service.impl.AdstDivideServiceImpl.myDivideDAO; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xwood.pms..dao.myDivideDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}”,详情日志如下
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDivideService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xwood.pms.dao.MyDivideDAO com.xwood.pms.service.impl.myDivideServiceImpl.MyDivideDAO; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xwood.pms.dao.MyDivideDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@ at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:298) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1148) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:636) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934) ~[spring-context-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at com.xwood.basic.sar.context.SARSpringContextFactory.create(SARSpringContextFactory.java:105) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.sar.JARContextBean.startup(JARContextBean.java:91) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.context.support.JARManagerBean._startupSAR(JARManagerBean.java:277) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.context.support.JARManagerBean.startup(JARManagerBean.java:260) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.context.support.JARManagerBean._startupSARs(JARManagerBean.java:172) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.context.support.JARManagerBean.startupSARs(JARManagerBean.java:99) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.context.XAppLifecycleBean.innnerStartup(XAppLifecycleBean.java:122) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.context.XAppLifecycleBean.start(XAppLifecycleBean.java:73) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.XAppContextBean.startup(XAppContextBean.java:142) [XApp-5.2.6.jar:5.2.6]@b@ at com.xwood.basic.test.SARContextLoader.loadContext(SARContextLoader.java:39) [XApp-5.2.6.jar:5.2.6]@b@ at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:75) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:95) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12-4.12.jar:4.12]@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12-4.12.jar:4.12]@b@ at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12-4.12.jar:4.12]@b@ at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12-4.12.jar:4.12]@b@ at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12-4.12.jar:4.12]@b@ at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12-4.12.jar:4.12]@b@ at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12-4.12.jar:4.12]@b@ at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) [spring-test-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) [.cp/:?]@b@ at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:?]@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) [.cp/:?]@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) [.cp/:?]@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) [.cp/:?]@b@ at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) [.cp/:?]@b@Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xwood.pms.dao.MyDivideDAO com.xwood.pms.service.impl.myDivideServiceImpl.adstDivideDAO; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xwood.pms.dao.MyDivideDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@ at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:531) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:295) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ ... 47 more@b@Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xwood.pms.dao.MyDivideDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}@b@ at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:997) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:867) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:779) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:503) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:295) ~[spring-beans-3.2.13.RELEASE-3.2.13.RELEASE.jar:3.2.13.RELEASE]@b@ ... 47 more
二、解决方法
因查询sql分页的时候错写为rownum<${endNum} ,应该改为rownum < ${endNum} ,问题即可解决了
<?xml version="1.0" encoding="UTF-8" ?> @b@<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">@b@<mapper namespace="com.xwood.bms.imsp.ldsp.dao.CityDAO"> @b@@b@<select id="getPageList" parameterType="com.xwood.bms.imsp.ldsp.dto.CityDTO" resultType="com.xwood.bms.imsp.ldsp.dto.CityDTO" > @b@ SELECT * FROM (@b@ SELECT *,ROWNUM rownum FROM (@b@ SELECT ID,CITY_NAME,CREATED_BY,UPDATED_BY,CREATED_DATE,UPDATED_DATE@b@ FROM CFSS_LDSP_CDD_CITY ORDER BY UPDATED_DATE DESC )) @b@ WHERE rownum <= #{endNum} AND rownum > #{startNum} @b@</select>@b@@b@</mapper>
修改结果如下
<?xml version="1.0" encoding="UTF-8" ?> @b@<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">@b@<mapper namespace="com.xwood.bms.imsp.ldsp.dao.CityDAO"> @b@@b@<select id="getPageList" parameterType="com.xwood.bms.imsp.ldsp.dto.CityDTO" resultType="com.xwood.bms.imsp.ldsp.dto.CityDTO" > @b@ SELECT * FROM (@b@ SELECT *,ROWNUM rownum FROM (@b@ SELECT ID,CITY_NAME,CREATED_BY,UPDATED_BY,CREATED_DATE,UPDATED_DATE@b@ FROM CFSS_LDSP_CDD_CITY ORDER BY UPDATED_DATE DESC )) @b@ WHERE rownum <= #{endNum} AND rownum > #{startNum} @b@</select>@b@@b@</mapper>