简体   繁体   English

创建依赖于Spring Boot并具有自己的bootstrap.yml的库

[英]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 测试项目

  • src/main/resources/bootstrap.yaml <- Anything I put in here works src / main / resources / bootstrap.yaml <-我在这里放的任何东西都可以

Library 图书馆

  • src/main/java/UserProperties <- Uses @ConfigurationProperties src / main / java / UserProperties <-使用@ConfigurationProperties
  • src/main/java/MyProperties <- Uses @ConfigurationProperties with a different Prefix src / main / java / MyProperties <-使用具有不同前缀的@ConfigurationProperties
  • src/main/resources/bootstrap.yaml <- Doesn't seem to do anything, but I want MyProperties to use this as a default. src / main / resources / bootstrap.yaml <-似乎什么也没做,但是我希望MyProperties将此作为默认值。

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.

相关问题 bootstrap.yml 未在 Spring Boot 2 中加载 - bootstrap.yml not loading in Spring Boot 2 在 spring boot 中将属性放在 application.yml 或 bootstrap.yml 上有什么区别? - What is the difference between putting a property on application.yml or bootstrap.yml in spring boot? Spring 引导:使用 bootstrap.yml 加载通用配置应用程序属性文件 - Spring Boot: Load common config application properties file using bootstrap.yml 在spring-boot类构造函数中调用first或bootstrap.yml? - In spring-boot Class constructor get called first or bootstrap.yml? 在 Spring 上未找到/读取 Bootstrap.yml 部署在 Tomcat 上的 Boot 2 应用程序 - Bootstrap.yml not being found/read on Spring Boot 2 application deployed on Tomcat 无法从spring-boot中的Properties文件和Bootstrap.yml中选择值 - Unable to pick the values from Properties file and Bootstrap.yml in spring-boot 是否需要 bootstrap.yml? - Is bootstrap.yml required? Spring Cloud 2020.0 不再处理 bootstrap.yml 配置 - bootstrap.yml configuration not processed anymore with Spring Cloud 2020.0 在 spring-cloud 项目中,可以完全用 bootstrap.yml 替换 application.yml 吗? - In spring-cloud project, is it ok to replace application.yml with bootstrap.yml totally? 使用Java而不是bootstrap.yml通过Eureka查找Spring Cloud Config Server - Spring Cloud Config Server lookup through Eureka using Java instead of bootstrap.yml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM