How do I use Spring Property Placeholder with Camel XML

 

How do I use Spring Property Placeholder with Camel XML

We do NOT yet support the ${something} notation inside arbitrary Camel XML. For example at the time of writing this is NOT supported (due Spring limitations)

IS NOT SUPPORTED
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
    ">

  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
    <route>
      <from uri="activemq:${someQueueName}"/>
      <to uri="mock:results"/>
    </route>
  </camelContext>

</beans>

However you can use the <endpoint/> element to define endpoints which does support the property resolving which you can then refer to by name, using the Ref component as shown below (notice the ref: in the uri):

SUPPORTED
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
    ">

  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
    <endpoint id="input1" uri="activemq:${someQueueName}"/>

    <route>
      <from uri="ref:input1"/>
      <to uri="activemq:OutputQueue"/>
    </route>
  </camelContext>

</beans>

Camel does not yet fully support property placeholders as there is a limitation in Spring. See JIRA SPR-4466

Bridge Spring and Camel property placeholders
From Camel 2.10 onwards you can bridge Spring and Camel property placeholders, see Using PropertyPlaceholder for more details.

Here is a trick that you can use to define the uri in a property file using Spring injection and Camel endpoint : http://cmoulliard.blogspot.com/2009/05/trick-to-pass-uri-declared-in-property.html.

From Camel 2.3 onwards there is a Properties component build in Camel core which allows you to use properties in the same way as Spring property placeholders, and even more.

http://camel.apache.org/how-do-i-use-spring-property-placeholder-with-camel-xml.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值