- spring中提示BeanCreationException
-
- 2015-05-24 22:16:48,030 ERROR [org.springframework.web.servlet.DispatcherServlet] - Context initialization failed
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aomRapsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.thinkgem.jeesite.modules.rap.service.AomRapsService com.thinkgem.jeesite.modules.rap.web.AomRapsController.somRapsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aomRapsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.thinkgem.jeesite.common.persistence.CrudDao com.thinkgem.jeesite.common.service.CrudService.dao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.thinkgem.jeesite.common.persistence.CrudDao] 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:301)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
- at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
- at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
- at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
- at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
- at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
- at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
- at javax.servlet.GenericServlet.init(GenericServlet.java:160)
- at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
- at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
- at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
- at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
- at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
- at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
- at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
- at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
- at java.lang.Thread.run(Thread.java:744)
- Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.thinkgem.jeesite.modules.rap.service.AomRapsService com.thinkgem.jeesite.modules.rap.web.AomRapsController.somRapsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aomRapsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.thinkgem.jeesite.common.persistence.CrudDao com.thinkgem.jeesite.common.service.CrudService.dao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.thinkgem.jeesite.common.persistence.CrudDao] 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:522)
- at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:298)
- ... 34 more
- Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aomRapsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.thinkgem.jeesite.common.persistence.CrudDao com.thinkgem.jeesite.common.service.CrudService.dao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.thinkgem.jeesite.common.persistence.CrudDao] 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:301)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:271)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1021)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:964)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:862)
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:494)
- ... 36 more
最佳回答:
@Autowired 會自動尋找你定義的這個class的類名的首字母小寫的spring bean的定義。所以這個取決於你用的這個AomRapsService是怎麼定義的。如果它也是通過在AomRapsService上面加上@Service的方式來定義,那spring會自動生成一個bean id="aomRapsService"的spring bean。但是如果這個class的定義是自己在spring xml裡面寫了一個bean id="AomRapsService"的spring bean,這種autowired的方式會失敗。解決方法是使用@Resource(name=“AomRapsService”)