Using properties loaded with spring in Mule EL

Here is a quick example how you can access you can access properties loaded using spring using the Mule expression language.

    <!-- configure property placeholder -->
    <context:property-placeholder location="classpath:application.properties"
                                  system-properties-mode="OVERRIDE"
                                  ignore-resource-not-found="false"
                                  ignore-unresolvable="false"/>
    <!-- configure bean to read the same properties -->
    <spring:beans>
        <spring:bean id="appProps"
                     class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <spring:property name="singleton" value="true"/>
            <spring:property name="location" value="classpath:application.properties"/>
            <spring:property name="properties">
                <spring:props>
                    <spring:prop key="key4">value4</spring:prop>
                </spring:props>
            </spring:property>
        </spring:bean>
    </spring:beans>

    <flow name="spring-property">
        <vm:inbound-endpoint exchange-pattern="request-response" path="springproperty.in">
            <logger message="Message received #[groovy:message.payload]" level="INFO"/>
            <!-- set a session scoped property on the message -->
            <message-properties-transformer scope="session">
                <add-message-property key="dynamickey" value="key4"/>
            </message-properties-transformer>
        </vm:inbound-endpoint>
        <!-- use the property placeholder, set once, not per message -->
        <logger message="key1 = ${key1}" level="INFO"/>
        <!-- use the appProps bean -->
        <logger message="key2 = #[[groovy:appProps.key2]]" level="INFO"/>
        <logger message="key3 = #[[groovy:appProps['key3']]]" level="INFO"/>
        <!-- access property value based on message property -->
        <logger message="key4 = #[[groovy:appProps[message.getSessionProperty('dynamickey')]]]" level="INFO"/>
        <append-string-transformer message="abc"/>
    </flow>
blog comments powered by Disqus