3

我正在使用 context:property-placeholder 通过属性文件加载各种值。我可以使用属性进行 Spring 注入和日志记录而不会出错,但是当我尝试在 MEL 表达式中评估它们时收到异常:

<spring:beans>
    <spring:bean id="someId" class="com.myClass">
        <!-- This works just fine -->
        <spring:constructor-arg index="0" value="${myVariable}" />
    </spring:bean>
</spring:beans>

<flow name="myFlow">
    <!-- exception here -->
    <choice>
        <when expression="#[${myVariable} == 'setting1']">
            <logger message="setting1 selected" level="WARN"/>
        </when>
        <otherwise>
            <logger message="setting1 NOT selected" level="WARN"/>
        </otherwise>
    </choice>
</flow>

错误是:

org.mule.exception.DefaultMessagingExceptionStrategy: Caught exception in Exception Strategy: null
java.lang.NullPointerException
at org.mule.routing.filters.ExpressionFilter.getFullExpression(ExpressionFilter.java:140)

关于如何检查 MEL 表达式中导入属性的值的任何想法?

这是完整的堆栈:

错误 2013-06-17 12:36:52,114 [defaultHttpConnector.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:在异常策略中捕获异常:null
java.lang.NullPointerException
    在 org.mule.routing.filters.ExpressionFilter.getFullExpression(ExpressionFilter.java:140)
    在 org.mule.routing.filters.ExpressionFilter.accept(ExpressionFilter.java:104)
    在 org.mule.routing.ChoiceRouter.selectProcessors(ChoiceRouter.java:35)
    在 org.mule.routing.AbstractSelectiveRouter.process(AbstractSelectiveRouter.java:194)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    在 org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:90)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    在 org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
    在 org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    在 org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:44)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    在 org.mule.construct.AbstractPipeline$1.process(AbstractPipeline.java:138)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    在 org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:195)
    在 org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:163)
    在 org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:150)
    在 org.mule.transport.vm.VMMessageReceiver.onCall(VMMessageReceiver.java:103)
    在 org.mule.transport.vm.VMMessageDispatcher$1.doInTransaction(VMMessageDispatcher.java:90)
    在 org.mule.transport.vm.VMMessageDispatcher$1.doInTransaction(VMMessageDispatcher.java:87)
    在 org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:45)
    在 org.mule.transport.vm.VMMessageDispatcher.doSend(VMMessageDispatcher.java:93)
    在 org.mule.transport.AbstractMessageDispatcher.process(AbstractMessageDispatcher.java:81)
    在 org.mule.transport.AbstractConnector$DispatcherMessageProcessor.process(AbstractConnector.java:2553)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    在 org.mule.endpoint.outbound.OutboundResponsePropertiesMessageProcessor.process(OutboundResponsePropertiesMessageProcessor.java:39)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    在 org.mule.processor.TransactionalInterceptingMessageProcessor$1.doInTransaction(TransactionalInterceptingMessageProcessor.java:49)
    在 org.mule.processor.TransactionalInterceptingMessageProcessor$1.doInTransaction(TransactionalInterceptingMessageProcessor.java:46)
    在 org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:45)
    在 org.mule.processor.TransactionalInterceptingMessageProcessor.process(TransactionalInterceptingMessageProcessor.java:55)
    在 org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    在 org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:44)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    在 org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    在 org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    在 org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    在 org.mule.endpoint.DefaultOutboundEndpoint.process(DefaultOutboundEndpoint.java:95)
    在 org.mule.routing.outbound.AbstractOutboundRouter.sendRequestEvent(AbstractOutboundRouter.java:461)
    在 org.mule.routing.outbound.AbstractOutboundRouter.sendRequest(AbstractOutboundRouter.java:167)
    在 org.mule.routing.outbound.FilteringOutboundRouter.route(FilteringOutboundRouter.java:80)
    在 org.mule.routing.outbound.OutboundPassThroughRouter.route(OutboundPassThroughRouter.java:71)
    在 org.mule.routing.outbound.AbstractOutboundRouter$1.doInTransaction(AbstractOutboundRouter.java:102)
    在 org.mule.routing.outbound.AbstractOutboundRouter$1.doInTransaction(AbstractOutboundRouter.java:99)
    在 org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:45)
    在 org.mule.routing.outbound.AbstractOutboundRouter.process(AbstractOutboundRouter.java:107)
    在 org.mule.component.DefaultInterfaceBinding.process(DefaultInterfaceBinding.java:45)
    在 org.mule.component.BindingInvocationHandler.invoke(BindingInvocationHandler.java:95)
4

1 回答 1

9

您需要用引号将其括起来,因为它是一个字符串:

<when expression="#['${myVariable}' == 'setting1']">

在 Mule 3.3.0 之前的版本中,您应该能够使用 Groovy:

<when evaluator="groovy" expression="'${myVariable}' == 'setting1'">
于 2013-06-17T17:40:51.590 回答