我正在使用 Spring Boot 創建一個多模塊專案。專案的結構是這樣的:
-configuration
|--- src
|--- main
|--- java
|--- resources
|--- build.gradle
-module1
|--- src
|--- main
|--- java
|--- resources
|--- build.gradle
-module2
|--- src
|--- main
|--- java
|--- resources
|--- build.gradle
build.gradle
settings.gradle
module1用于應用的持久化,其資源目錄包含檔案application.properties包含資料庫的配置以及data.sql和schema.sql
當我運行應用程式時,資源僅從“配置”模塊加載,而不是從module1加載。我的目標是加載所有模塊的所有資源檔案夾(因為每個模塊都有不同的職責)
uj5u.com熱心網友回復:
你能發布你收到的錯誤嗎?我的猜測是你需要一個@componentScan
,但看到錯誤會很有幫助。
uj5u.com熱心網友回復:
我找到了解決我的問題的方法,如下所示:
在配置模塊的build.gradle中,我添加了這個任務:
task copyResources(type: Copy) {
println "Copying resource"
from "${project(':module1').buildDir}/resources/main/schema.sql"
into "${buildDir}/resources/test"
from "${project(':module1').buildDir}/resources/main/data.sql"
into "${buildDir}/resources/test"
}
processResources.dependsOn copyResources
這將在構建時將 data.sql 和 schema.sql 從 module1 復制到配置模塊。然后當應用程式啟動(從配置模塊)時,它將使用這些復制的檔案,因為它們位于其資源檔案夾中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/434123.html