【问题标题】:Replace uri with property from configuration file in xml用xml中配置文件中的属性替换uri
【发布时间】:2020-07-20 19:31:40
【问题描述】:

如何将 uri 替换为配置文件 myprops.cfg 中的文本?

<route id="camel-http-proxy2">
   <from uri="jetty://http://127.0.0.1:5555/mock"/>
</route>

myprops.cfg:

myuri=http://127.0.0.1:555/mock

我的尝试:

<route id="camel-http-proxy2">
   <from uri="jetty://${myuri}"/>
</route>

然后骆驼按原样读取uri,它不会用属性的值替换它。
再试一次:

<endpoint id="input1" uri="jetty//${myuri}"/>

<route id="camel-http-proxy2">
  <from uri="ref:input1"/>
</route>

错误:

org.osgi.service.blueprint.container.ComponentDefinitionException: 无法验证 xml org.xml.sax.SAXParseException:cvc-complex-type.2.4.a:发现以元素“{”http://camel.apache.org/schema/blueprint“:endpoint}”开头的无效内容。需要 '{"http://camel.apache.org/schema/blueprint":route}' 之一。

【问题讨论】:

    标签: java xml spring apache-camel


    【解决方案1】:

    答案是:

    <route id="camel-http-proxy2">
      <from uri="jetty://{{myuri}}"/>
    </route>
    

    我认为骆驼的文档没有更新。

    【讨论】:

    • 如果您在camel.apache.org 网站上发现过时的内容。您可以使用该页面右上角的Edit this Page 链接并解决此问题吗?谢谢。
    【解决方案2】:

    您需要在属性占位符标签中添加配置文件。

    <cm:property-placeholder id="myblueprint.placeholder" persistent-id="myprops">
    

    然后您可以将该属性引用为${properties:myuri}{{myuri}}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      • 2012-08-25
      • 2017-05-27
      相关资源
      最近更新 更多