Search code examples
javaspring-bootspring-boot-configuration

Create Library that has a dependency on Spring Boot that has a it's own bootstrap.yml


I am working on a library that I want to have its own bootstrap.yaml to define some configurations. I already have a class that is used for user defined configurations in there bootstrap.yaml, but when I attempt to create another configuration class I am never able to get the values stored in my bootstrap.yaml, but it will take them from the users bootstrap.yaml.

How it looks:

Test Project

  • src/main/resources/bootstrap.yaml <- Anything I put in here works

Library

  • src/main/java/UserProperties <- Uses @ConfigurationProperties
  • src/main/java/MyProperties <- Uses @ConfigurationProperties with a different Prefix
  • src/main/resources/bootstrap.yaml <- Doesn't seem to do anything, but I want MyProperties to use this as a default.

I read somewhere that adding @PropertySource("classpath:bootstrap.yaml") to a MyProperties should work, but had no luck.


Solution

  • If I understood the question correctly then, one way is to create a configuration class and import the yaml file using PropertySource, then use @value annotation to assign the value to the member variables. Finally, you can @Import your config class in the main config class. Hopefully, it will help you