Expressing the Spring Expression Language via Mule

DZone 's Guide to

Expressing the Spring Expression Language via Mule

Mule easily uses the Spring Expression Language (SpEL) in its application. We will be creating a small Mule application to demonstrate the usage of SpEL in a Mule app.

· Integration Zone ·
Free Resource

We all might be familiar with the Spring Expression Language (SpEL), which is one of the powerful expression languages that supports querying and manipulating an object graph at runtime.

There are also several other expression languages available like OGNL, MVEL, MEL, and JBoss EL, but SpEL is undoubtedly one of the better performer and was created to provide the Spring community with a single well supported expression language that can be used across all the Spring products.

Mule has an old relationship with Spring and supports the Spring framework for developing Java applications. Mule has the advantage of creating and managing Spring application contexts for our Mule application. Mule XML configuration file uses Spring 4.1.6’s ability to create bean definition profiles.

Though Mule has its own expression language called MEL, which is based on the top of MVEL, we will see in this article how Mule easily uses the Spring Expression Language (SpEL) in its application. We will be creating a small Mule application to demonstrate the usage of SpEL in a Mule app.

Let’s start creating our application with following Java class:

package com.service;

public class PathAddress {

       private String path;

       private String basePath;

       public String getPath() {

              return path;


       public void setPath(String path) {

              this.path = path;


       public String getBasePath() {

              return basePath;


       public void setBasePath(String basePath) {

              this.basePath = basePath;


       public String myTestMethod() {

              return "Hi, This is a test method !";



We can see that we have defined two String values, path and basePath, that we will set in the URL of our application.

Let's look into our Mule flow:


     <spring:bean id="pathversion" class="com.service.PathAddress">

         <spring:property name="path" value="#{'test'}"/>

         <spring:property name="basePath" value="#{ systemProperties['base.path'] }"/>



    <http:listener-config name="HTTP_Listener_Configuration" basePath="#{pathversion.getBasePath()}" host="" port="8081" doc:name="HTTP Listener Configuration"/>

     <flow name="Flow">

         <http:listener config-ref="HTTP_Listener_Configuration" path="#{pathversion.getPath()}" doc:name="HTTP"/>

        <set-payload doc:name="Set Payload" value="#{pathversion.myTestMethod()}"/>

         <parse-template location="response.html" doc:name="Parse Template"/>


We can see here that we have defined the Spring bean and passing the values of the variables path and basePath from the bean. We have used SpEL to set the value of the variable elements.

For the path element, we have used SpEL to set the value directly as a string, whereas for the basePath element, we have used SpEL to set the value from the environment variable, which is defined in the app.properties file of our application:


Now, if you look in the XML, you can see that we have used SpEL to assign the values in the basePath for our HTTP listener connector as well as in our path of HTTP listener endpoint in the flow.

Further, we are calling our method myTestMethod() of the Java class using the SpEL.

At the end, we have added a basic HTML file in src/main/resources folder and call it in our flow using parse-template to spice up our response:



<title>Spring Expression Language Sample</title>




<b><font size="30" color="red">#[payload]</font></b>




Testing our Application

I we now deploy our application in server and test our application with this URL, we can see the result in the browser:

Image title


As we can see, we can easily use the powerful Spring Expression Language in our Mule application easily. Although Mule has its own MEL expression, we can implement SpEL side-by-side in our application as Mule is built on Spring and it offers flexibility to integrate this SpEL easily in our code.

mule ,spring ,integration ,expression language

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}