Reputation: 570
This is the structure of my project.
parent
| build.gradle
| settings.gradle
| [no code]
child1
| build.gradle
| src/
| main/
| java/
| resources/
| application.properties
| test/
| java/
| resources/
| application.properties
child2
| build.gradle
| src/
| main/
| java/
| test/
| java/
child3
| build.gradle
| src/
| main/
| java/
| test/
| java/
I have a property called "datapath" that I would like to inject into classes in each of the modules.
There are two possible values for "datapath", one for tests and one for production.
I set the production value in
child1/src/main/resources/application.properties
and the test value in
child1/src/test/resources/application.properties
I have tried creating configuration classes and specifying PropertySource. But the result has been that though child1 picks up the correct application properties in both test and main, spring does not find them in other modules.
Can you propose a strategy for me to implement this?
In particular:
Upvotes: 1
Views: 1081
Reputation: 4140
I assume that in child2
and child3
you need application.properties
only for test. Then in test you can use @TestPropertySource
where you can point relative path to properties file in child1
or add datapath
explicitly:
@TestPropertySource(properties = { "datapath=value" })
public class Child2Test {
Upvotes: 1