分享知識 傳遞快樂
使用 SpringBoot 搭建多子產品工程,在啟動時通路不到 *Service 或 *Dao 層,控制台顯示:
Description:
A component required a bean of type 'com.xh.pay.polling.service.TradePaymentRecordService' that could not be found.
Action:
Consider defining a bean of type 'com.xh.pay.polling.service.TradePaymentRecordService' in your configuration.
Process finished with exit code 1
解決辦法如下:
1、檢查 pom.xml 引入是否正确;
2、在 web 工程使用注解掃描指定路徑:
@SpringBootApplication
@ComponentScan("com.xh.pay.*.service") // 1. 多子產品項目需要掃描的包
@EnableJpaRepositories("***.***.***") // 2. Dao 層所在的包
@EntityScan("***.***.***") // 3. Entity 所在的包
此方式雖然可以對不同層級的目錄掃碼,但不易管理,增加的複雜性。
3、把帶有 @SpringBootApplication 注解的類放到所有子產品工程公共包路徑的父級即可。如圖: