2023年12月7日发(作者:)

springboot+mybatis报错找不到实体类的问题

目录

springboot+mybatis报错找不到实体类

找不到实体类的错误可能有很多,接下来列举几个地方

springboot+mybatis 找不到实体类问题

No qualifying bean of type‘rMapper‘ available

问题出现在

springboot+mybatis报错找不到实体类

找不到实体类的错误可能有很多,接下来列举几个地方

启动类位置不对,启动类应该在你的service和dao 的上一层,因为Spring是从启动类所在目录的同级目录开始扫描的,当然

你也可以放在其他地方,但需要配置,具体配置可以参考网上的其他文章!

文件的路劲配置是否正确,classpath指的是resources目录,如果不在resources目录下,注意正确配置路劲。

mapper接口类是否添加@Repository注解,表示这是数据访问组件。如果采用注解的形式使用mybatis需要加@Mapper

service层是否添加@Service注解,将bean注入到上下文中.

启动类是否添加@MapperScan(扫描mapper),@EntityScan(扫描实体类),如果启动类不在上面(1)所说的位置,则需要自己

添加@ComRepositor注解,自定义扫描的路径从中找出标识了需要装配的类自动装配到spring的bean容器中。

springboot+mybatis 找不到实体类问题

No qualifying bean of type‘rMapper‘ available

报错如下

2021-02-18 09:45:58,826 - Starting BfshApplication on DESKTOP-AAPVN38 with PID 10552

(F:IdeaIuwork_placebfshtargetclasses started by AoDexiusi in F:IdeaIuwork_placebfsh)

2021-02-18 09:45:58,828 - Running with Spring Boot E, Spring E

2021-02-18 09:45:58,829 - No active profile set, falling back to default profiles: default

2021-02-18 09:45:58,868 - Devtools property defaults active! Set '-properties' to 'false' todisable

2021-02-18 09:45:58,868 - For additional web related logging consider setting the '' property to

'DEBUG'

2021-02-18 09:45:59,438 - No MyBatis mapper was found in '[.*]' package. Please check your

configuration.

2021-02-18 09:45:59,809 - Tomcat initialized with port(s): 8888 (http)

2021-02-18 09:45:59,816 - Starting service [Tomcat]

2021-02-18 09:45:59,816 - Starting Servlet engine: [Apache Tomcat/9.0.41]

2021-02-18 09:45:59,925 - Initializing Spring embedded WebApplicationContext

2021-02-18 09:45:59,925 - Root WebApplicationContext: initialization completed in 1057 ms

2021-02-18 09:45:59,969 - Exception encountered during context initialization - cancelling refresh attempt:

eationException: Error creating bean with name 'sysUserController':

Injection of resource dependencies failed; nested exception is

eationException: Error creating bean with name 'sysUserServiceImpl':

Injection of resource dependencies failed; nested exception is

BeanDefinitionException: No qualifying bean of type

'rMapper' available: expected at least 1 bean which qualifies as autowire candidate.

Dependency annotations: {@ce(shareable=true, lookup=, name=, description=,

authenticationType=CONTAINER, type=class , mappedName=)}

2021-02-18 09:45:59,971 - Stopping service [Tomcat]

2021-02-18 09:45:59,978 - The web application [bfsh] appears to have started a thread named [Abandoned

connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of

thread:

(Native Method)

(:143)

(:40)

2021-02-18 09:45:59,986 -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2021-02-18 09:46:00,105 -

***************************

APPLICATION FAILED TO START

***************************

Description:

A component required a bean of type 'rMapper' that could not be found.

Action:

Consider defining a bean of type 'rMapper' in your configuration.

我的启动类:

@SpringBootApplication

@MapperScan(basePackages = ".*")

public class BfshApplication {

public static void main(String[] args) {

(, args);

}

}

项目结构:

问题出现在

@MapperScan(basePackages = “.*”)

修改为:

@MapperScan(basePackages = “”)

其实就是dao层扫描的位置不对。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。