2014-10-20 3 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

첫째, 그냥 낙타를 사용하기에 충분 것이다 : propertyPlaceholder 대신 콩 재산을 선언.

두 번째 실수는 당신의 time_inMilis 속성 값을 읽으려고 할 때 Constant 대신 Simple 표현으로 사용하고 있다는 점이다.

셋째, 당신 재산의 가치를 얻으려고 할 때, 당신은 구체적으로 당신의 재산을보고 있다고 말해야합니다. 당신의 문맥이 같은 propertiesPlaceholder을 정의하는 경우

: 자바 DSL과

<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> 

그들을 당신이 원래부터 봄 DSL 사용이

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

처럼 textProeprty 값을 읽을 수 있습니다 게시물을 읽는 올바른 방법은 다음과 같습니다.

<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

+0

답변이 유용 할 경우 투표하십시오 – Seego