加载 application.properties 当配置服务器未解析。

huangapple go评论143阅读模式
英文:

Load application.properties when the config server is not resolved

问题

我的项目有一个bootstrap.yaml和一个配置服务器,它们提供了适当的配置文件。一切都运行得很好,但我还需要完成一些其他的任务,比如持续集成和持续交付。

我的问题是,因为Jenkins机器不允许解析外部域名,它试图在没有配置文件的情况下编译和运行Spring Boot应用程序。

所以我的问题是:

  1. 在配置服务器未解析时,是否有一种加载application.properties的方法?
英文:

My project has a bootstrap.yaml and a config server that deliver its appropriate profile. Everything is working great but I have to accomplish some others task like CI and CD.

My problem comes because the Jenkins machine is not allowed to resolved external domains and try to compile and run the Spring boot app without an a profile.

So my question is:

  1. Is there a way to load application.properties when the config server
    is not resolved?

答案1

得分: 1

是的,有一种基于Spring Boot加载PropertySource顺序的自然方式。

您可以在application.properties中包含要应用的属性。

如果配置服务器不可用 - 将使用application.properties中的属性。如果配置服务器可用 - 您将从那里接收属性。

您还可能希望使用环境变量SPRING_CLOUD_CONFIG_ENABLED=false禁用CI的配置服务器连接。

英文:

Yes, there is a natural way based on the order in which Spring Boot loads PropertySources.

You can include properties you want to be applied in application.properties.

In case config server is not available - properties from application.properties will be used. If config server is available - you'll receive properties from there.

You might also want to disable config server connectivity for your CI using environment variable SPRING_CLOUD_CONFIG_ENABLED=false.

huangapple
  • 本文由 发表于 2020年10月27日 20:48:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64554786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定