Spring Boot + JPA 多模塊項目無法注入 JpaRepository 接口


問題描述

Spring Boot + JPA 多模塊項目,啟動報異常:

nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type '***.***.***Dao' available: 
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}

解決方案

在啟動類添加 @ComponentScan, @EnableJpaRepositories, @EntityScan 注解:

@SpringBootApplication
@ComponentScan("***.***") // 1. 多模塊項目需要掃描的包
@EnableJpaRepositories("***.***.***") // 2. Dao 層所在的包 
@EntityScan("***.***.***") // 3. Entity 所在的包

參考:SpringBoot JPA 中無法注入 JpaRepository 接口@ComponentScan無效

本人 C# 轉 Java 的 newbie, 如有錯誤或不足歡迎指正,謝謝


免責聲明!

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



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