2 qq 27422325 qq_27422325 于 2015.06.07 18:50 提问

spring mvc 报错,求解答,各位好心人必有好报。

六月 07, 2015 6:55:04 下午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.entity.Test com.test.service.impl.TestServiceImpl.test; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.test.entity.Test] 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:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
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:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.entity.Test com.test.service.impl.TestServiceImpl.test; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.test.entity.Test] 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:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
... 22 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.test.entity.Test] 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:949)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 24 more
求解啊

3个回答

SuperStonne
SuperStonne   2015.06.07 19:06
已采纳

如果你是为了加载spring mvc的配置文件而在web.xml中配置了listener,那么请注意如下:
使用的web容器支持servlet 2.3 或者更高版本的,你可以在web.xml 配置

org.springframework.web.context.ContextLoaderListener

使用的web容器支持servlet2.2 或者较低版本的或者支持2.3,但是在初始化servlet之前并没有初始化listener,你可以在web.xml中配置

context
org.springframework.web.context.ContextLoaderServlet
1

希望对你有用

SuperStonne
SuperStonne   2015.06.07 19:09

补充一下,刚刚的配置文件忘记添加到代码了。
如果你是为了加载spring mvc的配置文件而在web.xml中配置了listener,那么请注意如下:
使用的web容器支持servlet 2.3 或者更高版本的,你可以在web.xml 配置

 <listener>
<listener-class>org.springframework.
web.context.ContextLoaderListener</listener-class>
</listener>

使用的web容器支持servlet2.2 或者较低版本的或者支持2.3,但是在初始化servlet之前并没有初始化listener,你可以在web.xml中配置

 <servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.
web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

希望对你有用

qq_27422325
qq_27422325 我看了下是我在实体类上加了个@Autowired导致的
2 年多之前 回复
qq_27422325
qq_27422325 谢谢,不过不是这个原因早晨的
2 年多之前 回复
cuiwei1026522829
cuiwei1026522829   Ds   Rxr 2015.06.07 22:32

Could not autowire field: private com.test.entity.Test com.test.service.impl.TestServiceImpl.test; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
注入域,这个类中bean没有,配置的问题吧

qq_27422325
qq_27422325 我看了下是我在实体类上加了个@Autowired导致的
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片