【问题集萃】N004:SpringBoot2启动扫描Mapper失败:Field userInfoMapper in XXX that could not be found.

SpringBoot2启动扫描Mapper失败:Field userInfoMapper in XXX that could not be found.

Description:

Field userInfoMapper in com.gavinbj.confmng.service.impl.UserInfoServiceImpl required a bean of type 'com.gavinbj.confmng.persistence.mapper.UserInfoMapper' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.gavinbj.confmng.persistence.mapper.UserInfoMapper' in your configuration.

原因:

注入失败,SpringBoot扫描不到相应的Mapper文件。

对策:

方案一:在每个Mapper文件上添加@Mapper注解。

方案二:在应用的Application(启动类)上统一使用@MapperScan。(推荐)

package com.gavinbj.confmng;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 *  @SpringBootApplication 标注这是SpringBoot项目的主程序类
 */
@MapperScan("com.gavinbj.confmng.persistence.mapper")
@SpringBootApplication
public class ConfManageApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConfManageApplication.class, args);
	}

}
发布了24 篇原创文章 · 获赞 12 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/gavinbj/article/details/104076811