Spring+mybatis possible causes of injection failure using annotations

Source: Internet
Author: User

An error similar to the following occurred:

Severity: Exception sending context initialized event to listener instance of class Org.springframework.web.context.ContextLoad Erlistener
Org.springframework.beans.factory.BeanCreationException: Error creating Bean with Name ' Userserviceimpl ': Injection of autowired dependencies failed;Nested exception is org.springframework.beans.factory.BeanCreationException:Could not Autowire field:private Cn.springmvc.dao.UserDAO Cn.springmvc.service.impl.UserServiceImpl.userDAO; Nested exception is Org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type [ Cn.springmvc.dao.UserDAO] found for dependency:expected at least 1 beans which qualifies as Autowire candidate for this de Pendency. 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:1116)

At Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean ( abstractautowirecapablebeanfactory.java:519)

Possible causes:

1, whether in DAO, service, controller separately annotated

@Repository
@Service ("Xxxservice")
@Controller ("Xxxcontroller")
And
@Resource (name = "Xxxservice")
private Xxxservice xxxservice;
2. Whether the following components are configured in the Spring configuration file

<!--turn on the note processor--
<context:annotation-config/>
<!--enable spring MVC annotations, default annotation mapping support--
<mvc:annotation-driven/>
<context:component-scan base-package= "Com.xxx.xxx.dao,com.xxx.xxx.service,com.xxx.xxx.controller" >
</context:component-scan>
3. Check if the Web. xml file loads the spring and MyBatis configuration files

4. Check that the annotation name is consistent

5, check the Spring Profile Scan mapper and DAO interface is configured correctly


These details may be overlooked, although it is common to develop commonly used configurations, but if omitted, there will be errors, in the moment not to think of these









Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.