gpt4 book ai didi

java - 如何在 mule MEL 表达式中使用属性变量?

转载 作者:行者123 更新时间:2023-12-01 09:00:57 28 4
gpt4 key购买 nike

我正在使用 context:property-placeholder 通过属性文件加载各种值。我可以将属性用于 Spring 注入(inject)和日志记录而不会出错,但是当我尝试在 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 表达式中导入属性的值的任何想法?

这是完整的堆栈:

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

最佳答案

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

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

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

<when evaluator="groovy" expression="'${myVariable}' == 'setting1'">

关于java - 如何在 mule MEL 表达式中使用属性变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17153510/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com