Injection of autowired dependencies failed; autowire 自动注入失败,测试类已初始化过了Spring容器。
Posted antgo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Injection of autowired dependencies failed; autowire 自动注入失败,测试类已初始化过了Spring容器。相关的知识,希望对你有一定的参考价值。
1 严重: StandardWrapper.Throwable 2 org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘searchController‘: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.e3mall.search.service.SearchService cn.e3mall.search.controller.SearchController.searchService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘searchService‘: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service cn.e3mall.search.service.SearchService. No provider available for the service cn.e3mall.search.service.SearchService from the url zookeeper://192.168.25.128:2181/com.alibaba.dubbo.registry.RegistryService?application=e3-search-web&dubbo=2.5.3&interface=cn.e3mall.search.service.SearchService&methods=search&pid=18424&revision=0.0.1-SNAPSHOT&side=consumer×tamp=1531915212587 to the consumer 192.168.25.1 use dubbo version 2.5.3 3 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 4 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 5 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 6 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 7 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 8 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 9 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 10 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 11 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) 12 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) 13 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) 14 at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) 15 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634) 16 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682) 17 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) 18 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) 19 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 20 at javax.servlet.GenericServlet.init(GenericServlet.java:160) 21 at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) 22 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193) 23 at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088) 24 at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176) 25 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460) 26 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 27 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 28 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 29 at java.util.concurrent.FutureTask.run(FutureTask.java:266) 30 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 31 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 32 at java.lang.Thread.run(Thread.java:748) 33 Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.e3mall.search.service.SearchService cn.e3mall.search.controller.SearchController.searchService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘searchService‘: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service cn.e3mall.search.service.SearchService. No provider available for the service cn.e3mall.search.service.SearchService from the url zookeeper://192.168.25.128:2181/com.alibaba.dubbo.registry.RegistryService?application=e3-search-web&dubbo=2.5.3&interface=cn.e3mall.search.service.SearchService&methods=search&pid=18424&revision=0.0.1-SNAPSHOT&side=consumer×tamp=1531915212587 to the consumer 192.168.25.1 use dubbo version 2.5.3 34 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) 35 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 36 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) 37 ... 29 more 38 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘searchService‘: FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service cn.e3mall.search.service.SearchService. No provider available for the service cn.e3mall.search.service.SearchService from the url zookeeper://192.168.25.128:2181/com.alibaba.dubbo.registry.RegistryService?application=e3-search-web&dubbo=2.5.3&interface=cn.e3mall.search.service.SearchService&methods=search&pid=18424&revision=0.0.1-SNAPSHOT&side=consumer×tamp=1531915212587 to the consumer 192.168.25.1 use dubbo version 2.5.3 39 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) 40 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) 41 at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1585) 42 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) 43 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 44 at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) 45 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) 46 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) 47 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) 48 ... 31 more 49 Caused by: java.lang.IllegalStateException: Failed to check the status of the service cn.e3mall.search.service.SearchService. No provider available for the service cn.e3mall.search.service.SearchService from the url zookeeper://192.168.25.128:2181/com.alibaba.dubbo.registry.RegistryService?application=e3-search-web&dubbo=2.5.3&interface=cn.e3mall.search.service.SearchService&methods=search&pid=18424&revision=0.0.1-SNAPSHOT&side=consumer×tamp=1531915212587 to the consumer 192.168.25.1 use dubbo version 2.5.3 50 at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:420) 51 at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:300) 52 at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:138) 53 at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65) 54 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) 55 ... 39 more 56 57 七月 18, 2018 8:00:21 下午 org.apache.catalina.core.StandardContext loadOnStartup 58 严重: Servlet threw load() exception 59 java.lang.IllegalStateException: Failed to check the status of the service cn.e3mall.search.service.SearchService. No provider available for the service cn.e3mall.search.service.SearchService from the url zookeeper://192.168.25.128:2181/com.alibaba.dubbo.registry.RegistryService?application=e3-search-web&dubbo=2.5.3&interface=cn.e3mall.search.service.SearchService&methods=search&pid=18424&revision=0.0.1-SNAPSHOT&side=consumer×tamp=1531915212587 to the consumer 192.168.25.1 use dubbo version 2.5.3 60 at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:420) 61 at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:300) 62 at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:138) 63 at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:65) 64 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) 65 at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) 66 at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1585) 67 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) 68 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 69 at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) 70 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) 71 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) 72 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) 73 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 74 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) 75 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 76 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 77 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 78 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 79 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 80 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 81 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 82 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) 83 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) 84 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) 85 at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) 86 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634) 87 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682) 88 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) 89 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) 90 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 91 at javax.servlet.GenericServlet.init(GenericServlet.java:160) 92 at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) 93 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193) 94 at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088) 95 at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176) 96 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460) 97 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 98 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 99 at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 100 at java.util.concurrent.FutureTask.run(FutureTask.java:266) 101 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 102 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 103 at java.lang.Thread.run(Thread.java:748)
tomcat启动工程,实际上是 用tomcat 初始化 Spring容器。出错就出在这里。
大意了。我在写测试类的时候 手动初始化 Spring 容器,测试没有启动tomcat工程 用Junit,后来没有 注释掉测试类,还保留原来的初始化的Spring
导致了 运行tomcat 网页测试的时候 老是出现 自动注入失败。
经过排查 applicationContext.service.xml 的扫描包 和 web.xml 监听都没有问题
最后注销了 测试代码。保存发布。重启发布tomcat
clean tomcat7:run
问题解决。
以上是关于Injection of autowired dependencies failed; autowire 自动注入失败,测试类已初始化过了Spring容器。的主要内容,如果未能解决你的问题,请参考以下文章
异常:Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentExceptio
@Repository 注解引发的异常: Injection of autowired dependencies failed; nested exception is org.springframe
Field injection is not recommended和Could not autowired. No beans of 'xxx' type found.
spring整合mybatis时运行测试代码报错Injection of autowired dependencies failed,请各位大神帮忙看看