class=”markdown_views prism-atom-one-dark”>
Error message:
Error creating bean with name 'atUserAction': Unsatisfied dependency expressed through field 'atUserService';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'cn.overloard.service.AtUserService' available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
This error means that the bean injection failed, we can find it in the order of container initialization.
1. Look at web.xml first. There is a listener configured here, especially classpath: This parameter must be checked to see if it matches the name of the configuration file.
<listener
listener-classorg.springframework.web.context.ContextLoaderListener</listener -class
</listener
context-param
param-namecontextConfigLocation</param-name
param-valueclasspath:applicationContext-*.xml</param-value
</context-param>
2. Check the applicationContext.xml and springMVC.xml files. In general projects, it is injected by package scanning, so check if the
scanned package path is correct.
applicationContext.xml
context:component-scan base-package="cn.overloard">
context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component- scan
springMVC.xml
context:component-scan base-package= "cn.overloard" use-default-filters="false"
context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component- scan
3. Check if there is any annotation in the class that you forgot to write
Generally, one of these @Controller, @Service, @Repository, @Component annotations
Such as:
@Service
public class AtUserServiceImpl implements AtUserService{
}
@Controller
public class AtUserAction {
}
4. If you configure beans through xml. You need to check whether the id and class are correct.
bean id="persion" class="cn.overloard.utils.Persion"/>