Spring Boot獲取依賴項目中定義的bean

在A項目中定義類了一些bean,並用Spring的@Component註解標識了。

在B項目中引用了A項目,即在pom.xml的dependency中添加了項目A。

在SpringBoot啓動的時候報找不到A項目中的bean。

因爲SpringBoot的啓動Application的默認的ComponentScan的範圍中沒有包含A項目的bean所在的package路徑。
在B項目中增加@ComponentScan(“com.package.where.projectA.class.is”)。

參考:https://stackoverflow.com/questions/29571304/how-can-i-autowire-a-spring-bean-that-was-created-from-an-external-jar

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章