Consider defining a bean of type 'com.xxx.mapper.XsMapper' in your configuration

详细描述:

Field xsMapper in com.xxx.controller.XsController required a bean of type 'com.xxx.mapper.XsMapper' 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.xxx.mapper.XsMapper' in your configuration.

 

解决:

这个是没有指定mybatis扫包的范围,sb不知道去哪里装载。

1)在Application类中指定扫包的范围

@MapperScan("包"),包:就是你的Mapper Interface所在包

2)可以直接在类上面加注解

直接在mapper接口上加@Mapper

说明:

如果二个都加行不行?答案:不行。今天突然试了一下,发现二个都加也行。:)自已亲测吧。

如果找不到:@MapperScan,应该咱办呢?

那肯定是要加入一个mybatis的

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

 这样就OK了。二种方案,二选一。

 

 

原文地址:https://www.cnblogs.com/jiduoduo/p/14072133.html