• ssm框架报错:Error creating bean with name 'XXXX': Injection of autowired dependencies failed; 原因和解决方法


    一、报错

    1、报错显示

      2、报错信息

      

    25-Nov-2019 15:32:19.746 警告 [RMI TCP Connection(5)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.refresh Exception encountered during context initialization - cancelling 
    refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is 
    org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.shixun.service.UserService com.shixun.controller.UserController.userService; nested exception is 
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.shixun.service.UserService] 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)}
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
            at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
            at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
            at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
            at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4685)
            at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
            at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1728)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
            at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
            at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
            at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:456)
            at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:405)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
            at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
            at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
            at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
            at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
            at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
            at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
            at java.security.AccessController.doPrivileged(Native Method)
            at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408)
            at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
            at sun.rmi.transport.Transport$1.run(Transport.java:200)
            at sun.rmi.transport.Transport$1.run(Transport.java:197)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            at java.lang.Thread.run(Thread.java:748)
        Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.shixun.service.UserService com.shixun.controller.UserController.userService; nested 
    exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.shixun.service.UserService] 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)}
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)
            at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
            ... 60 more
        Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.shixun.service.UserService] 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)}
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1326)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1072)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967)
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)
      3、关键报错信息
    Could not autowire field: private com.shixun.service.UserService com.shixun.controller.UserController.userService;   

    二、解决

    1、查看配置文件applicationContext.xml

    2、 spring-mvc配置

     所有配置文件可以通过在idea的点击,查看是否正常跳转,如果正常跳转则配置成功,如果没有则未配置成功,如我前两张图的扫描位置之前都配置错误

    3、impl文件【本人的错误在此】一定要加@Service和@Autowired

  • 相关阅读:
    codeforces.com/problemset/problem/213/C
    资源Createwindow,对应标识符,绑定窗口
    字符编码地址空间
    该来的还是要来,数据挖掘
    深信服准备
    K-Sum
    2017.3.20下午
    2017.3.20上午
    2017.3.17下午
    2017.3.17上午
  • 原文地址:https://www.cnblogs.com/hahayixiao/p/11933363.html
Copyright © 2020-2023  润新知