亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

springboot+mybatis報錯找不到實體類的問題

 更新時間:2022年01月17日 15:25:35   作者:zlhmeng  
這篇文章主要介紹了springboot+mybatis報錯找不到實體類的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

springboot+mybatis報錯找不到實體類

找不到實體類的錯誤可能有很多,接下來列舉幾個地方

啟動類位置不對,啟動類應(yīng)該在你的service和dao 的上一層,因為Spring是從啟動類所在目錄的同級目錄開始掃描的,當然你也可以放在其他地方,但需要配置,具體配置可以參考網(wǎng)上的其他文章!

在這里插入圖片描述

mapper.xml文件的路勁配置是否正確,classpath指的是resources目錄,如果不在resources目錄下,注意正確配置路勁。

在這里插入圖片描述

mapper接口類是否添加@Repository注解,表示這是數(shù)據(jù)訪問組件。如果采用注解的形式使用mybatis需要加@Mapper

在這里插入圖片描述

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

在這里插入圖片描述

啟動類是否添加@MapperScan(掃描mapper),@EntityScan(掃描實體類),如果啟動類不在上面(1)所說的位置,則需要自己添加@ComRepositor注解,自定義掃描的路徑從中找出標識了需要裝配的類自動裝配到spring的bean容器中。

springboot+mybatis 找不到實體類問題

No qualifying bean of type‘com.wj.bfsh.mapper.SysUserMapper‘ available

報錯如下

2021-02-18 09:45:58,826 - Starting BfshApplication on DESKTOP-AAPVN38 with PID 10552 (F:\IdeaIu\work_place\bfsh\target\classes started by AoDexiusi in F:\IdeaIu\work_place\bfsh)
2021-02-18 09:45:58,828 - Running with Spring Boot v2.3.7.RELEASE, Spring v5.2.12.RELEASE
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 'spring.devtools.add-properties' to 'false' to disable
2021-02-18 09:45:58,868 - For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-02-18 09:45:59,438 - No MyBatis mapper was found in '[com.wj.bfsh.mapper.*]' 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: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysUserController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysUserServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.wj.bfsh.mapper.SysUserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, 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:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java: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 'com.wj.bfsh.mapper.SysUserMapper' that could not be found.


Action:

Consider defining a bean of type 'com.wj.bfsh.mapper.SysUserMapper' in your configuration.

我的啟動類:

@SpringBootApplication
@MapperScan(basePackages = "com.wj.bfsh.mapper.*")
public class BfshApplication {
    public static void main(String[] args) {
        SpringApplication.run(BfshApplication.class, args);
    }
}

項目結(jié)構(gòu):

在這里插入圖片描述

問題出現(xiàn)在

@MapperScan(basePackages = “com.wj.bfsh.mapper.*”)

修改為:

@MapperScan(basePackages = “com.wj.bfsh.mapper”)

其實就是dao層掃描的位置不對。

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring Transaction事務(wù)實現(xiàn)流程源碼解析

    Spring Transaction事務(wù)實現(xiàn)流程源碼解析

    此文就Spring 事務(wù)實現(xiàn)流程進行源碼解析,我們可以借此對Spring框架更多一層理解,下面以xml形式創(chuàng)建一個事務(wù)進行分析
    2022-09-09
  • spring-data-jpa實現(xiàn)增刪改查以及分頁操作方法

    spring-data-jpa實現(xiàn)增刪改查以及分頁操作方法

    下面小編就為大家分享一篇spring-data-jpa實現(xiàn)增刪改查以及分頁操作方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • RocketMQ事務(wù)消息保證消息的可靠性和一致性

    RocketMQ事務(wù)消息保證消息的可靠性和一致性

    RocketMQ事務(wù)消息是一種能夠保證消息傳遞的可靠性和一致性的消息傳遞模式。它通過引入“半消息”和“事務(wù)狀態(tài)”機制,實現(xiàn)了消息發(fā)送和本地事務(wù)執(zhí)行的原子性,從而確保了消息的可靠性和一致性
    2023-04-04
  • 必須掌握的十個Lambda表達式簡化代碼提高生產(chǎn)力

    必須掌握的十個Lambda表達式簡化代碼提高生產(chǎn)力

    這篇文章主要為大家介紹了必須掌握的十個Lambda表達式來簡化代碼提高生產(chǎn)力,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-04-04
  • Spring?Boot超大文件上傳實現(xiàn)秒傳功能

    Spring?Boot超大文件上傳實現(xiàn)秒傳功能

    這篇文章主要介紹了Spring?Boot超大文件上傳實現(xiàn)秒傳功能,在實現(xiàn)分片上傳的過程,需要前端和后端配合,比如前后端的上傳塊號的文件大小,前后端必須得要一致,否則上傳就會有問題,需要的朋友可以參考下
    2022-12-12
  • Restful傳遞數(shù)組參數(shù)及注解大全

    Restful傳遞數(shù)組參數(shù)及注解大全

    這篇文章主要介紹了Restful傳遞數(shù)組參數(shù)及注解大全的相關(guān)資料,需要的朋友可以參考下
    2015-12-12
  • IDEA Maven源修改為國內(nèi)阿里云鏡像的正確方式

    IDEA Maven源修改為國內(nèi)阿里云鏡像的正確方式

    為了加快 Maven 依賴的下載速度,可以將 Maven 的中央倉庫源修改為國內(nèi)的鏡像,比如阿里云鏡像,以下是如何在 IntelliJ IDEA 中將 Maven 源修改為阿里云鏡像的詳細步驟,感興趣的同學(xué)可以參考閱讀一下
    2024-09-09
  • java從鍵盤輸入數(shù)字并判斷大小的方法

    java從鍵盤輸入數(shù)字并判斷大小的方法

    今天小編就為大家分享一篇java從鍵盤輸入數(shù)字并判斷大小的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • mybatis-plus復(fù)合主鍵的使用

    mybatis-plus復(fù)合主鍵的使用

    本文主要介紹了mybatis-plus復(fù)合主鍵的使用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Apache Shrio安全框架實現(xiàn)原理及實例詳解

    Apache Shrio安全框架實現(xiàn)原理及實例詳解

    這篇文章主要介紹了Apache Shrio安全框架實現(xiàn)原理及實例詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-04-04

最新評論