轉載:https://blog.csdn.net/qq_38537709/article/details/104750598
問題描述
A模塊的controller類依賴B模塊的Service類,項目運行時報錯
Parameter 0 of constructor in com.example.multimodule.application.DemoApplication required a bean of type 'com.example.multiservice.MyService' that could not be found.
- 1
A模塊 controller類包名 | B模塊 service類包名 | A模塊包掃描路徑 | 依賴 |
---|---|---|---|
com.example.multimodule.application | com.example.multimodule.service | com.example.multimodule | 成功 |
com.example.multimodule.application | com.example.service | com.example.multimodule | 失敗 |
com.example.multimodule.application | com.example.service | com.example | 成功 |
問題解決辦法
- 擴大包掃描路徑范圍
- 將依賴不成功的包名添加到包掃描路徑下
本質上是一個包掃描的問題。