mule dataweave调用spring bean

时间:2017-06-22 19:43:04

标签: mule resourcebundle anypoint-studio dataweave

我定义了一个spring bean来处理我的应用程序的资源包,如下所示:

<spring:bean id="renewMobileEngagementApiMessages" class="org.springframework.context.support.ResourceBundleMessageSource">
    <spring:property name="basename" value="messages/renew-mobile-engagement-api-messages"></spring:property>
    <spring:property name="defaultEncoding" value="UTF-8"></spring:property>
    <spring:property name="fallbackToSystemLocale" value="false"></spring:property>
</spring:bean>

在我的应用程序中,我可以在变量或记录器对象中访问它,例如使用以下MEL命令:

#[app.registry.renewMobileEngagementApiMessages.getMessage('error.clic_unavailable.description', null, sessionVars.REQUESTED_LOCALE)]

它按预期正确返回我的属性,直到这里没问题。

问题是现在我需要在dw:transform-message中访问我的属性,而我无法弄清楚如何去做。我尝试使用全局功能,但我没有得到如何访问我的&#34; renewMobileEngagementApiMessages&#34;对象引用然后调用&#34; getMessage&#34;方法

任何帮助都会很棒。提前谢谢!

4 个答案:

答案 0 :(得分:0)

只需将消息放入带有MEL的dataweave组件之前的flowVar或有效负载中,然后访问数据编织中的payload / flowVar。

这里有一个例子,我在我的数据编辑访问它之前将我的spring bean加载到有效负载中:

{{1}}

答案 1 :(得分:0)

您可以在dataweave组件之前将该属性存储在流变量中,并使用flowVars

dataweave中调用此flowVars.variableName

答案 2 :(得分:0)

您可以使用运算符'p()'

轻松访问任何系统或Spring属性

示例:

%dw 1.0
%output application/json
---
{
    mulehome: p('mule.home')
}

答案 3 :(得分:0)

当DataWeave处理您的转换时,您可以引用服务器中存在的任何属性(系统或弹簧),这样做是使用p(&#39; prop_name&#39;)函数。