Spring Cloud Config Client - Java配置HashMap或属性

问题描述 投票:0回答:1

我是MicroServices,eureka和spring的新手......

我想启动我的Eureka客户端,从我创建的HashMap中获取值,然后再启动云信息所在的应用程序。

HashMap config = new HashMap ();
config.put ("spring_cloud_config_enabled", "true");
config.put ("spring_application_name", "MicroService");
config.put ("spring_profiles_active", "default");
config.put ("spring_cloud_config_uri", "http://myHost:8888");

如果为空,请访问bootstrap.properties信息。

有谁知道我怎么能这样做?谢谢!

spring spring-boot netflix-eureka spring-cloud-netflix spring-cloud-config
1个回答
0
投票

以下是spring应用程序中加载属性的顺序:

  1. bootstrap.properties/压马路
  2. 本地application.properties/yaml
  3. 命令行覆盖
  4. Cloud Config基于应用程序/配置文件的属性

加载/超越以上述格式发生。因此,您可以根据您的要求决定回退逻辑。

外部加载总结如下link

从那里添加提取物

  1. 在您的主目录上开发全局设置属性(当devtools处于活动状态时,〜/ .spring-boot-devtools.properties)。
  2. @TestPropertySource测试注释。
  3. 测试中的@ SpringBootTest#properties annotation属性。
  4. 命令行参数。
  5. SPRING_APPLICATION_JSON中的属性(嵌入在环境变量或系统属性中的内联JSON)。
  6. ServletConfig初始化参数。
  7. ServletContext init参数。
  8. 来自java:comp / env的JNDI属性。
  9. Java系统属性(System.getProperties())。
  10. OS环境变量。
  11. RandomValuePropertySource,只具有随机属性。*。
  12. 特定于配置文件的应用程序属性在打包的jar之外(application- {profile} .properties和YAML变体)。
  13. 打包在jar中的特定于配置文件的应用程序属性(application- {profile} .properties和YAML变体)。
  14. 打包jar之外的应用程序属性(application.properties和YAML变体)。
  15. 打包在jar中的应用程序属性(application.properties和YAML变体)。
  16. @Configuration类上的@PropertySource注释。
  17. 默认属性(通过设置SpringApplication.setDefaultProperties指定)。
© www.soinside.com 2019 - 2024. All rights reserved.