2016-12-16 71 views
-1

我在camel.config駱駝配置讀屬性文件中的值

<choice> 
    <when> 
     <simple>${BROADBAND_DN_RBSID_SWITCH} == 'DN'</simple> 
      <to uri="bean:bbGetServiceProfileProcessorByDN"/> 
    </when> 
</choice> 

我讀其他文件即spring.properties $ {} BROADBAND_DN_RBSID_SWITCH值 #temp switch BROADBAND_DN_RBSID_SWITCH=DN

但我得到以下定義狂勝以下錯誤

Message History 
--------------------------------------------------------------------------------------------------------------------------------------- 
RouteId    ProcessorId   Processor                  Elapsed (ms) 
[BROADBAND-ROUTES ] [BROADBAND-ROUTES ] [direct://BROADBAND               ] [  380] 
[BROADBAND-ROUTES ] [multicast4  ] [multicast                  ] [  380] 
[BROADBAND-ROUTES ] [choice17   ] [when[simple{${BROADBAND_DN_RBSID_SWITCH} == 'DN'}]choice[]     ] [  14] 

    Stacktrace 
--------------------------------------------------------------------------------------------------------------------------------------- 
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-INPUSCPC08541-53313-1481817337243-0-29] 
    at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1696) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.builder.SimpleBuilder.createPredicate(SimpleBuilder.java:104) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.builder.SimpleBuilder.matches(SimpleBuilder.java:83) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.FilterProcessor.matches(FilterProcessor.java:65) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:93) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468) [camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) [camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) [camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.MulticastProcessor.doProcessParallel(MulticastProcessor.java:814) [camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.MulticastProcessor.access$200(MulticastProcessor.java:84) [camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:314) [camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.processor.MulticastProcessor$1.call(MulticastProcessor.java:299) [camel-core-2.17.0.jar:2.17.0] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_45] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_45] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_45] 
    at java.lang.Thread.run(Thread.java:744) [?:1.7.0_45] 
Caused by: org.apache.camel.language.simple.types.SimpleIllegalSyntaxException: Unknown function: BROADBAND_DN_RBSID_SWITCH at location 0 
${BROADBAND_DN_RBSID_SWITCH} == 'DN' 
* 

    at org.apache.camel.language.simple.SimplePredicateParser.parsePredicate(SimplePredicateParser.java:69) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.SimpleLanguage.createPredicate(SimpleLanguage.java:115) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.builder.SimpleBuilder.createPredicate(SimpleBuilder.java:102) ~[camel-core-2.17.0.jar:2.17.0] 
    ... 16 more 
Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: BROADBAND_DN_RBSID_SWITCH 
    at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createSimpleExpression(SimpleFunctionExpression.java:216) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createExpression(SimpleFunctionExpression.java:40) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.ast.SimpleFunctionStart.doCreateLiteralExpression(SimpleFunctionStart.java:58) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.ast.SimpleFunctionStart.createExpression(SimpleFunctionStart.java:48) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.ast.BinaryExpression.createExpression(BinaryExpression.java:78) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.SimplePredicateParser.createPredicates(SimplePredicateParser.java:438) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.SimplePredicateParser.doParsePredicate(SimplePredicateParser.java:119) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.SimplePredicateParser.parsePredicate(SimplePredicateParser.java:66) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.language.simple.SimpleLanguage.createPredicate(SimpleLanguage.java:115) ~[camel-core-2.17.0.jar:2.17.0] 
    at org.apache.camel.builder.SimpleBuilder.createPredicate(SimpleBuilder.java:102) ~[camel-core-2.17.0.jar:2.17.0] 
    ... 16 more 

回答

1

您不能在簡單語言中使用${xxx}來引用屬性placeho lder連續。而是使用其properties功能:

<simple>${properties:BROADBAND_DN_RBSID_SWITCH} == 'DN'</simple> 

多見於文檔:http://camel.apache.org/simple

0

其他可能的解決方案: 您可以定義財產持有人對駱駝上下文:

<camelContext id="my-camel-context"> 
    <propertyPlaceholder 
     location="file:${config.path}/my.properties" id="properties" /> 

注意,在這個級別你可以使用普通Spring或System的其他屬性(例如$ {config.path})

然後在路由E可以使用{{符號作爲

<simple>{{BROADBAND_DN_RBSID_SWITCH}} == 'DN'</simple> 

駱駝propertyPlaceholder具有比較正規春PropertyPlaceholder限制,但只是文件它工作正常。