Field baseMapper in xxxxx required a bean of type 'xxxxxx' that could not be found 问题

最近在整合spring boot 和通用mapper时遇到错误,纠结了好长时间,先看错误

Description:Field baseMapper in com.sinosoft.common.mybatis.service.impl.BaseServiceImpl required a bean of type 'com.sinosoft.common.mybatis.mapper.MyBaseMapper' that could not be found.Action:Consider defining a bean of type 'com.sinosoft.common.mybatis.mapper.MyBaseMapper' in your configuration.Process finished with exit code 1

问题解决思路
1.先看下pom,下边是整合通用mapper所须的依赖

 
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
        dependency>

        
        <dependency>
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
            <version>1.3.0version>
        dependency>

        
        <dependency>
            <groupId>com.github.pagehelpergroupId>
            <artifactId>pagehelper-spring-boot-starterartifactId>
            <version>1.2.3version>
        dependency>

        
        <dependency>
            <groupId>tk.mybatisgroupId>
            <artifactId>mapper-spring-boot-starterartifactId>
            <version>2.0.2version>
        dependency>


        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
            <version>1.0.18version>
        dependency>

2.代码目录结构

Field baseMapper in xxxxx required a bean of type 'xxxxxx' that could not be found 问题_第1张图片
3.需要检查的点
3.1basemapper 不能和业务类的mapper放在同一目录下
Field baseMapper in xxxxx required a bean of type 'xxxxxx' that could not be found 问题_第2张图片
3.2service实现类应该抽象的避免被通用mapper扫描

public abstract class BaseServiceImpl<T,ID extends Serializable> implements BaseService<T,ID> {
    @Autowired
    public MyBaseMapper baseMapper;

3.3业务类mapper应该加上@Mapper注解,或者在spring boot启动类上添加@MapperScan注解

@Mapper
public interface MusicMapper extends MyBaseMapper<MusicModel> {
}
@SpringBootApplication
@MapperScan(basePackages ={"com.sinosoft.musicproxy.mapper"})
public class MusicProxyApplication  {
    public static void main(String[] args) {
        SpringApplication.run(MusicProxyApplication.class, args);
    }
}

3.4业务类应该继承你自己的通用mapper接口。我自己的错误就是吧MyBaseMapper写成了BaseMapper(这个错误是真的低级)

//错误
@Mapper
public interface MusicMapper extends BaseMapper<MusicModel> {
}

//正确
@Mapper
public interface MusicMapper extends MyBaseMapper<MusicModel> {
}

3.5namespace对应接口名

<mapper namespace="com.sinosoft.musicproxy.mapper.MusicMapper" >
package com.sinosoft.musicproxy.mapper;

/**
 * @author fxl
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018-06-149:55
 */
@Mapper
public interface MusicMapper extends BaseMapper<MusicModel> {
}

3.6.还有可能是你的某些mapper没有加@mapper注解,也会出现这种情况
这算我在遇到这个问题在网上找到解决方法吧,希望别有人跟我一样犯同样的错误,特别是低级错误。写的不好,见谅。

你可能感兴趣的:(Field baseMapper in xxxxx required a bean of type 'xxxxxx' that could not be found 问题)