SSM项目No qualifying bean of type 问题常见解决方法
错误信息如下
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'cn.resume.service.impl.UserServiceImpl' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
常见解决方法:
- 检查spring核心配置文件是否扫描了当前类所在的包
- 当前类是否有 @Service @Component等注解,当前类是否被@Bean初始化
- ssm项目检查是否web.xml配置文件是否有关联spring核心配置文件
解决方法:在web.xml中添加监听器并且声明应用范围(整个WEB项目)内的上下文初始化参数。代码如下
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>