zoukankan      html  css  js  c++  java
  • springboot 启动报错Consider defining a bean of type 'com.example.springbootdruid.mapper.UserMapper' in your configurati

    一、问题

    springboot项目启动时报错:

    Field userMapper in com.example.springbootdruid.service.impl.UserServiceImpl required a bean of type 'com.example.springbootdruid.mapper.UserMapper' that could not be found.

    原因是因为没有扫描到对应的类

    二、解决方式:

    1、检查配置文件是否写对:

      在springboot的配置文件添加,mybatis的配置如下所示:

    mybatis:
    type-aliases-package: com.xxx.xxx.domain
    mapper-locations: classpath:/mybatis/*.xml

     2、是否加上相应的注解

      在启动类上加上@MapperScan或者@ComponentScan注解,手动指定application类要扫描哪些包下的注解,如下所示: 

    @SpringBootApplication
    @MappertScan(basePackages = {"com.xxx.xxx.mapper"})

      或者在接口上添加@Mapper注解。

    @Mapper
    public interface UserMapper {
    }

    注意检查涉及到的包路径是否写正确。

  • 相关阅读:
    hdu--2522--循环节
    hdu--2523--读懂题意....
    hdu--1073--字符串处理
    hdu--1114--完全背包
    C#写入对象到XML/从XML读取对象
    C#打开另一个窗体
    Intent启动照片或者相机
    ViewGroup
    上传文件的表单
    添加菜单到fragment
  • 原文地址:https://www.cnblogs.com/kingsonfu/p/10344388.html
Copyright © 2011-2022 走看看