【錯誤分析】Field productMapper in org.spring.springboot.service.impl.ProductServiceImpl required a bean of type 'org.spring.springboot.mapper.ProductMapper' that could not be found.報錯,找不到mapper的bean。


1.運行項目,控制台出現以下錯誤:

***************************
APPLICATION FAILED TO START
應用程序啟動失敗
***************************

Description:
描述

Field productMapper in org.spring.springboot.service.impl.ProductServiceImpl required a bean of type 'org.spring.springboot.mapper.ProductMapper' that could not be found.
在org.spring.springboot.service.impl中的字段productMapper。ProductServiceImpl需要一個“org.spring.springboot.mapper”類型的bean。沒有找到ProductMapper。

Action:
建議
    
Consider defining a bean of type 'org.spring.springboot.mapper.ProductMapper' in your configuration.
    
考慮定義一個“org.spring.springboot.mapper”類型的bean。在您的配置中的ProductMapper。

2.解決辦法:當我看到這個錯誤時,我首先認為我在ProductMapper文件中沒有寫注解,讓ProductServiceImpl調用ProductMapper是找不到bean,但我發現並沒有少寫注解。后來發現原來是主函數上@MapperScan("org.spring.springboot.mapper")沒寫明地址。當添加完畢再次運行,就完全沒有問題了。

@SpringBootApplication
@MapperScan("org.spring.springboot.mapper")
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

}

 

3.總結:@MapperScan("mapper路徑") 可以掃描接口包 @MapperScan({"mapper路徑","mapper路徑"}) 掃描多個接口包


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM