Mapper interface injection failure problem after spring MyBatis consolidation

Source: Internet
Author: User

Org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying Bean of type [ Com.fkhd.whiteshirt.daos.UserMapper] found for dependency:expected at least 1 bean which qualifies as Autowire For this dependency. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (Required=true)}

Spring-mybatis:

  <!--spring and MyBatis are perfectly integrated and do not require mybatis configuration mapping files--> <bean id= "Sqlsessionfactory"  
    Org.mybatis.spring.SqlSessionFactoryBean ">  
       <property name=" DataSource "  
     ref=" Localdatasource "/>" <property name= "mapperlocations" value= "Classpath:mapper/*.xml" ></property>
    </bean>  
	
	 <!--the package name of the DAO interface, Spring automatically finds the class-->  
    <bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" below it >  
        <property name= "basepackage" value= "Com.fkhd.whiteshirt.daos"/> <property name=  
        " Sqlsessionfactorybeanname "value=" sqlsessionfactory "></property>
    </bean>

Serviceimpl:

@Autowired
 private Usermapper usermapper;

Modify Serviceimpl to:

@Autowired (required=false)
 private Usermapper usermapper;

No error, but usermapper null, also do not inject, so that the solution is not an error, but the project can not continue, so find another way.

All the solutions have been tried, not resolved, so they are looking back at their own projects.

My reason for the error in: Web.xml boot is not loaded soring-mybatis.xml, plus later problem solving.

My reason for this is that Web.xml is not loaded, just a problem. Can see if you are loading, if loaded to see other reasons!

Configurations that can be run:

Spring-mybatis (not modified):

  <!--spring and MyBatis are perfectly integrated and do not require mybatis configuration mapping files--> <bean id= "Sqlsessionfactory"  
    Org.mybatis.spring.SqlSessionFactoryBean ">  
       <property name=" DataSource "  
     ref=" Localdatasource "/>" <property name= "mapperlocations" value= "Classpath:mapper/*.xml" ></property>
    </bean>  
	
	 <!--the package name of the DAO interface, Spring automatically finds the class-->  
    <bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" below it >  
        <property name= "basepackage" value= "Com.fkhd.whiteshirt.daos"/> <property name=  
        " Sqlsessionfactorybeanname "value=" sqlsessionfactory "></property>
    </bean>

Serviceimpl (not modified):

@Autowired
 private Usermapper usermapper;




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.