将XML中的uri替换为配置文件中的property

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

Replace uri with property from configuration file in xml

问题

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

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

How can I replace the uri with the text from configuration file myprops.cfg?

&lt;route id=&quot;camel-http-proxy2&quot;&gt;
   &lt;from uri=&quot;jetty://http://127.0.0.1:5555/mock&quot;/&gt;
&lt;/route&gt;

myprops.cfg:

myuri=http://127.0.0.1:555/mock

my try:

&lt;route id=&quot;camel-http-proxy2&quot;&gt;
   &lt;from uri=&quot;jetty://${myuri}&quot;/&gt;
&lt;/route&gt;

Then the camel read the uri as it is, it doesnt replace it with the value of the property.
another try:

&lt;endpoint id=&quot;input1&quot; uri=&quot;jetty//${myuri}&quot;/&gt;

&lt;route id=&quot;camel-http-proxy2&quot;&gt;
  &lt;from uri=&quot;ref:input1&quot;/&gt;
&lt;/route&gt;

error:
> org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to validate xml
>org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://camel.apache.org/schema/blueprint":endpoint}'. One of '{"http://camel.apache.org/schema/blueprint":route}' is expected.

答案1

得分: 1

答案是:

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

Camel的文档可能没有更新。

英文:

The answer is:

&lt;route id=&quot;camel-http-proxy2&quot;&gt;
  &lt;from uri=&quot;jetty://{{myuri}}&quot;/&gt;
&lt;/route&gt;

The documentation of camel is not updated I think.

答案2

得分: 1

你需要将配置文件添加到property-placeholder标签内。

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

然后可以通过${properties:myuri}{{myuri}}来引用该属性。

英文:

You need to add the config file within the property-placeholder tag.

&lt;cm:property-placeholder id=&quot;myblueprint.placeholder&quot; persistent-id=&quot;myprops&quot;&gt;

You can then reference the property as ${properties:myuri} or {{myuri}}

huangapple
  • 本文由 发表于 2020年4月8日 19:41:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/61099822.html
匿名

发表评论

匿名网友

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

确定