简体   繁体   English

Spring 引导:使用 bootstrap.yml 加载通用配置应用程序属性文件

[英]Spring Boot: Load common config application properties file using bootstrap.yml

In our config server we have following application properties files:在我们的配置服务器中,我们有以下应用程序属性文件:

helloApp-dev.properties //dev env properties
helloApp-commonConfig.properties //common properties across env

The properties are accessible from URI like:可以从 URI 访问这些属性,例如:

https://myapp.abc.com/1234/helloApp-dev.properties
https://myapp.abc.com/1234/helloApp-commonConfig.properties

Below is our bootstrap.yml of helloApp application:下面是我们的 helloApp 应用程序的 bootstrap.yml:

---
spring:
  application:
    name: helloApp
    
---
spring  
  profiles: dev
  cloud:
    config:
      label: 1234
      name: {spring.application.name}
      uri: https://myapp.abc.com/

I am using Spring boot version 2.2.4.我正在使用 Spring 启动版本 2.2.4。 The helloApp-dev.properties are loading successfully in application but not commonConfig. helloApp-dev.properties 在应用程序中成功加载,但不是 commonConfig。

To load properties file, profiles should match.要加载属性文件,配置文件应该匹配。 You have 2 solutions:您有 2 个解决方案:

  1. Rename helloApp-commonConfig.properties -> helloApp.properties重命名helloApp-commonConfig.properties -> helloApp.properties
  2. Use multiple profiles for your application ( dev , commonConfig )为您的应用程序使用多个配置文件( devcommonConfig

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从spring-boot中的Properties文件和Bootstrap.yml中选择值 - Unable to pick the values from Properties file and Bootstrap.yml in spring-boot 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? 在bootstrap.yml中不使用spring.application.name,在冲突情况下在application.properties中使用 - spring.application.name is not honoured in bootstrap.yml instead honoured in application.properties in conflicting case 在 Spring 上未找到/读取 Bootstrap.yml 部署在 Tomcat 上的 Boot 2 应用程序 - Bootstrap.yml not being found/read on Spring Boot 2 application deployed on Tomcat 使用Java而不是bootstrap.yml通过Eureka查找Spring Cloud Config Server - Spring Cloud Config Server lookup through Eureka using Java instead of bootstrap.yml Spring Boot 不加载 application.yml 配置 - Spring Boot doesn't load application.yml config 在 spring-cloud 项目中,可以完全用 bootstrap.yml 替换 application.yml 吗? - In spring-cloud project, is it ok to replace application.yml with bootstrap.yml totally? Spring Boot - 从依赖的 jar 加载 application.properties/yml - Spring Boot - Load application.properties/yml from dependent jar 如何在Spring Boot应用程序中从YML文件加载多个属性 - How to load multiple properties from YML file in spring-boot application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM