There is always an error in configuring the SPRINGMVC framework as follows:
java.lang.IllegalStateException:Failed to load ApplicationContext at Org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext ( cacheawarecontextloaderdelegate.java:99) at Org.springframework.test.context.TestContext.getApplicationContext ( testcontext.java:122) at Org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary ( servlettestexecutionlistener.java:105) at Org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance ( servlettestexecutionlistener.java:74) at Org.springframework.test.context.TestContextManager.prepareTestInstance (testcontextmanager.java:312) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest ( springjunit4classrunner.java:211) at org.springframework.test.context.junit4.springjunit4classrunner$1. Runreflectivecall (springjunit4classrunner.java:288) at Org.junit.internal.runners.model.ReflectiveCallable.run ( REFLECTIVECALLABLE.JAVA:12) at Org.springframeworK.test.context.junit4.springjunit4classrunner.methodblock (springjunit4classrunner.java:284) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:231) at Org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild (springjunit4classrunner.java:88) 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:174) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (junit4testreference.java:46) 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.factory.BeanCreationException:Error creating bean with Name ' login ': Injection of autowired Dependencies failed; Nested exception is org.springframework.beans.factory.BeanCreationException:Could not Autowire field:private Com.rest.tiis.service.UserService Com.rest.tiis.controller.Login.userService; Nested exception is Org.springframEwork.beans.factory.NoSuchBeanDefinitionException:No qualifying Bean of type [Com.rest.tiis.service.UserService] Found for dependency:expected at least 1 beans which qualifies as autowire for this candidate. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (Required=true)} at Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ( autowiredannotationbeanpostprocessor.java:288) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean ( abstractautowirecapablebeanfactory.java:1116) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:519) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean ( abstractautowirecapablebeanfactory.java:458) at org.springframework.beans.factory.support.abstractbeanfactory$1.
GetObject (abstractbeanfactory.java:295) At Org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton ( defaultsingletonbeanregistry.java:223) at Org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (abstractbeanfactory.java:292) at Org.springframework.beans.factory.support.AbstractBeanFactory.getBean (abstractbeanfactory.java:194) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons ( defaultlistablebeanfactory.java:628) at Org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization ( abstractapplicationcontext.java:932) at Org.springframework.context.support.AbstractApplicationContext.refresh ( abstractapplicationcontext.java:479) at Org.springframework.test.context.support.AbstractGenericContextLoader.loadContext ( ABSTRACTGENERICCONTEXTLOADER.JAVA:120) at Org.springframework.test.context.support.AbstractGenericContextLoader.loadContext ( ABSTRACTGENERICCONTEXTLOADER.JAVA:60) at org.springframework.test.coNtext.support.AbstractDelegatingSmartContextLoader.delegateLoading (Abstractdelegatingsmartcontextloader.java : (Org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext) at abstractdelegatingsmartcontextloader.java:248) at Org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal ( CACHEAWARECONTEXTLOADERDELEGATE.JAVA:64) at Org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext ( cacheawarecontextloaderdelegate.java:91) ... caused by:org.springframework.beans.factory.BeanCreationException:Could not autowire field:private Com.rest.tiis.service.UserService Com.rest.tiis.controller.Login.userService; Nested exception is Org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [ Com.rest.tiis.service.UserService] found for dependency:expected at least 1 bean which qualifies as Autowire candidate fo R this dependency. Dependency annotations: {@org. springframework.Beans.factory.annotation.Autowired (Required=true)} at Org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject (autowiredannotationbeanpostprocessor.java:514) at Org.springframework.beans.factory.annotation.InjectionMetadata.inject (injectionmetadata.java:87) at Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ( autowiredannotationbeanpostprocessor.java:285) ... More caused By:org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [com.rest . Tiis.service.UserService] found for dependency:expected at least 1 beans which qualifies as autowire for this D Ependency. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (Required=true)} at Org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException ( defaultlistablebeanfactory.java:988) at Org.springframework.beaNs.factory.support.DefaultListableBeanFactory.doResolveDependency (defaultlistablebeanfactory.java:858) at Org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency ( defaultlistablebeanfactory.java:770) at Org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject (autowiredannotationbeanpostprocessor.java:486) ...
More
Finally found that I need to rely on injecting controller, service two packages, but at first I just automatically relied on injected controller such as:
<!--automatic scanning-->
<context:component-scan base-package= "Com.rest.tiis.controller"/>
Modified into:
<!--auto Scan-->
<context:component-scan base-package= "Com.rest.tiis.controller"/>
<context: Component-scan base-package= "Com.rest.tiis.service"/>
The above is my personal package name.
Problem solved instantly, two hours, just so ...
All summed up is:
We will only use, do not know the bottom of the end is how to design, always stay in the application level, it is difficult to improve coding efficiency. Read more, read more source code, more exchanges ...