Mapper problem cannot be scanned when Springboot integrated MyBatis

Source: Internet
Author: User
Tags aliases

Integrate with Springboot with the MyBatis official starter

<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId> mybatis-spring-boot-starter</artifactid>
            <version>1.1.1</version>
</dependency >

There is no problem starting the project in the IDE, but the following exception occurs when you hit the Jar startup project:

15:51:43.909 [main] DEBUG O.s.b.d.loggingfailureanalysisreporter-application failed to start due to an exception
org . Springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying Bean found for dependency [ Org.zbt.service.jxc.dao.base.DataDicMapper]: Expected at least 1 bean which qualifies as Autowire candidate. Dependency annotations: {@org. springframework.beans.factory.annotation.Autowired (Required=true)} at
        Org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound ( defaultlistablebeanfactory.java:1463)
 ...
 .... Org.springframework.boot.starter.dubbo.startup.BootStrap.main (bootstrap.java:15)
2016-11-13 15:51:44.389 ERROR 3349---[           

The exception can be known because mapper is not springboot scanned.
The configurable parameters provided by the official are only available in a few:

Config-location MyBatis XML config file (optional)
mapper-locations    mapper xml config files (optional)
Type-aliases-package package to    search for type aliases (optional)
Type-handlers-package package to   search For type aliases (optional)
executor-type   executor type:simple, Reuse, BATCH (optional)
configuration   A MyBatis Configuration Bean

You can see that the location of the Mapper interface cannot be specified.
You can resolve this issue by adding the following configuration to the spring file that can be loaded into the springboot:

<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" >
          <property name= "Basepackage" value = "Org.zbt.service.jxc.dao.base"/>
          <property name= "Annotationclass" value= " Org.apache.ibatis.annotations.Mapper "/>
</bean>

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.