I'm creating a multimodule project using Spring Boot. the structure of the project is like this:
-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 is for the persistence of the application, and its resources directory contains the file application.properties containing the configuration of the database and also data.sql and schema.sql
When I run the application the resources are loaded only from the "configuration" module and not from module1. my goal is to load all the resources folders of all the modules (since each module has a different responsibility)
CodePudding user response:
Could you post the error you receive?
My guess is you need a @componentScan
but it would be much helpful to see the error.
CodePudding user response:
I found a solution to my issue like this:
in build.gradle of the configuration module I added this task:
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
This will copy the data.sql and schema.sql from module1 to the configuration module at build time. and then when application start (from the configuration module) it will use those copied files as they are located in its resources folder.