2

I have two spring boot projects, Project A and Project B, each with its own application.properties.

When the project is run individually the values from application.properties are injected properly. But when I am using one of the Project B as a dependency in Project A, the default values defined in application.properties of B are not being injected and I have to define the same properties again in the .properties file of A which is kind of redundant.

How do I avoid this? I want the default values in the properties file of B to be injected and I would only want to define the properties for B when I want to override the default values. Sorry for my english

Clint
  • 2,696
  • 23
  • 42

2 Answers2

1

AFAIK, there is no out-of-box solution for this. I would recommend two solutions and you can go with one more feasible for you:

  1. Take out all properties common for all projects and put them in a seperate properties file, use them with @PropertySource.

  2. Use spring cloud config to store common(or all) properties. You can also have some custom logic there to pick the correct property among multiple property files.

Agam
  • 1,015
  • 2
  • 11
  • 21
0

It's hard to say without your code provided. I guess you can try to use multiple .properties files for Project A application like following:

@PropertySources({
        @PropertySource(name = "propsA", value = "classpath:propsA.properties"),
        @PropertySource(name = "propsB", value = "classpath:propsB.properties")
})
public class ApplicationA {
Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42