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 {
}

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

相关文章:

  • 2021-12-16
  • 2021-07-09
  • 2021-10-13
  • 2021-04-24
  • 2021-07-07
  • 2021-08-31
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2021-08-02
  • 2021-05-24
  • 2022-12-23
  • 2021-05-05
相关资源
相似解决方案