I'm developing a spring boot app and starter. I want the starter to hold common properties and code.
In my starter I have an application-dev.properties file. I have defined a @Profile("dev") in the starter.
When I start my app using the dev profile I see properties from the starter, which is great. What's not great is when I add an application-dev.properties file to my app, the one from the starter is no longer read at all. This means I can't figure out how to put common "dev" profile properties in there.
Based on the external configuration documentation I assumed this would work because the starter file would be read and then the app file.
Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:
SNIP
Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
Any suggestions?
Putting application-dev.properties into src/main/resources/config folder for your starter and putting application-dev.properties of your app into src/main/resources should help resolve this problem.
I think adding application-dev.properties
to starter is not good idea. The problem is you can add the file only once. Well, you may put the file into folder config
. It means you can add the file at most twice. No more. What if you decide to use second starter; where you put application-dev.properties
then?
I think application*.properties
should be added to end user product only. For portable module I propose to use
- @PropertySource annotations on your @Configuration classes.
@Configuration
@PropertySource("classpath:/my/starter/dev.properties")
@Profile("dev")
public class MyConf {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With