[英]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. 我正在开发一个图书馆,希望拥有自己的bootstrap.yaml来定义一些配置。 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. 我已经有一个用于在bootstrap.yaml中用于用户定义的配置的类,但是当我尝试创建另一个配置类时,我永远无法获取存储在bootstrap.yaml中的值,但是它将从用户那里获取它们。 bootstrap.yaml。
How it looks: 外观:
Test Project 测试项目
Library 图书馆
@ConfigurationProperties
src / main / java / UserProperties <-使用@ConfigurationProperties
@ConfigurationProperties
with a different Prefix src / main / java / MyProperties <-使用具有不同前缀的@ConfigurationProperties
I read somewhere that adding @PropertySource("classpath:bootstrap.yaml")
to a MyProperties should work, but had no luck. 我在某处读到,将@PropertySource("classpath:bootstrap.yaml")
到MyProperties应该可以,但是没有运气。
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. 如果我正确理解了问题,那么一种方法是创建一个配置类,然后使用PropertySource导入yaml文件,然后使用@value批注将值分配给成员变量。 Finally, you can @Import your config class in the main config class. 最后,您可以在主配置类中@Import您的配置类。 Hopefully, it will help you 希望对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.