2014-10-20 124 views
1

我想从属性文件中读取时间延迟。从属性文件读骆驼常量

在我的属性文件中定义:

time_inMilis=15000 

我已经配置我的骆驼背景下的XML是:

<bean id="property" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <value>file:/D:/Develop/resources/my.properties 
      </value> 
     </property> 
    </bean> 


    <camel:camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> 

    <propertyPlaceholder id="properties" location="file:/D:/Develop/resources/my.properties"/> 

     <camel:route id="delayQueue"> 
      <camel:from uri="seda:queue1" /> 
      <delay asyncDelayed="true"> 
       <constant>${time_inMilis}</constant> 
      </delay> 
      <camel:to uri="seda:queue2" /> 
     </camel:route> 

    </camel:camelContext> 

骆驼不抛出任何错误,但它似乎忽略$ {time_inMilis }并为我的延迟时间设置为0。

什么是从我的属性文件中读取延迟常量的正确方法?

回答

2

首先,只需使用即可:camel:propertyPlaceholder而不是声明bean 属性

第二个错误是,你尝试阅读time_inMilis属性值时使用的Constant代替Simple表达。

第三,当试图获得你的财产价值时,你应该特别告诉骆驼你正在看财产。

如果上下文定义propertiesPlaceholder这样的:

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> 
    <propertyPlaceholder id="props" location="classpath:/org/smp/eip/sample.properties"/> 
    <package>org.apache.camel.example.spring</package> 
</camelContext> 

他们与Java DSL你就可以读取textProeprty值这样

from("file:src/data?noop=true") 
    .transform().simple("Text read from properties: ${properties:textProperty}") 
    .bean(new SomeBean()); 

从原来的使用Spring DSL后,正确的阅读方式是:

<camel:route id="delayQueue"> 
     <camel:from uri="seda:queue1" /> 
     <delay asyncDelayed="true"> 
      <simple>${properties:time_inMilis}</simple> 
     </delay> 
     <camel:to uri="seda:queue2" /> 
    </camel:route> 
+0

非常感谢!效果不错 – lshaked 2014-10-20 14:52:43

+0

如果答案有用,请将其投票 – Seego 2014-10-21 08:08:18