【问题标题】:variable substitution in properties file not working in spring boot 1.x and apache camel2.x属性文件中的变量替换在 spring boot 1.x 和 apache camel2.x 中不起作用
【发布时间】:2021-08-26 15:19:20
【问题描述】:

我在 application.properties 文件中声明了一个属性,如下所示

hu.ednpoint=https://${serverhost.name}/subscription/event
de.ednpoint=https://${serverhost.name}/consume/event 

我预计 ${serverhost.name} 的值将被 api.xfjj.com:443 覆盖,但它会给出以下结果 访问值骆驼路线

.log("{{hu.ednpoint}}")
.log("{{de.ednpoint}}")
.to("{{de.ednpoint}}")
.end() 

预期结果:

hu.ednpoint=https://api.xfjj.com:443/subscription/event
de.ednpoint=https://api.xfjj.com:443/consume/event

实际结果:

hu.ednpoint=https:/subscription/event
de.ednpoint=https:/consume/event

我不确定哪里出了问题。如果有人能帮我解决这个问题,我真的很感激。这个问题发生在 camel2 但在 camel3 工作正常

【问题讨论】:

  • 这是实际的结果还是你自己凭记忆打出来的?因为在那个结果中双斜线消失了,所以缺少的不仅仅是变量值。
  • 是的,这是最终结果 // 双斜线也不见了
  • 那么问题不在于 serverhost.name 属性。 Maven 参与了这个项目吗?如果是这样,它是否被配置为进行资源过滤?
  • 您如何检查实际结果?我的意思是你如何以及在哪里获取这些属性?
  • @hjoeren 是的,我知道,我只是在解释您的评论(您说 Jar 中的属性没有被替换)。正如您所说,它正在运行时,所以我同意您的看法。它可以在运行时正常工作,没有任何问题。但是需要从 OP 中澄清如何以及在何处访问属性。

标签: java spring spring-boot apache-camel spring-camel


【解决方案1】:

您能否尝试使用 yaml 而不是属性文件。 例如。

apiConfig:
    pf:
      host:
        name: api.xfjj.com:443
      uri:
        base:
          admin: https://${apiConfig.pf.host.name}/
        apis:
          orders:
            get:
              subscription: ${apiConfig.pf.uri.base.admin}/suscription/event/
              consume:${apiConfig.pf.uri.base.admin}/consume/event/

【讨论】:

  • 我不能这样做,因为应用程序是单片的并且它有 application.properties 文件
  • 在这种情况下,您可以将serverhost.name 设置为环境变量,而不是属性文件中的属性。
猜你喜欢
  • 2017-02-20
  • 2016-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多