Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Configuring Properties

This page describes configuring properties, such as property placeholders and system properties.

Property Placeholders

You can use Ant-style property placeholders in your Mule ESB configuration. For example:


         
      
1
<smtp:outbound-endpoint user="${smtp.username}" password="${smtp.password}"/>

The values for these placeholders can be made available in a variety of ways, as described in the sections below.

Global Properties

You can use the <global-property> element to set a placeholder value from within your Mule configuration, such as from within another Mule configuration file:


         
      
1
2
<global-property name="smtp.username" value="JSmith"/>
<global-property name="smtp.password" value="ChangeMe"/>

Properties Files

To load properties from a file, you can use the standard Spring element

<context:property-placeholder>:


         
      
1
2
3
4
5
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
  
<context:property-placeholder location="smtp.properties"/>

where the contents of smtp.properties is:


         
      
1
2
smtp.username=JSmith
smtp.password=ChangeMe

To load multiple properties files, separate them with commas:


         
      
1
<context:property-placeholder location="email.properties,http.properties,system.properties" placeholderPrefix="${"/>

Message Properties

You can use placeholders to perform logic on message properties such as the header. For example, if you wanted to evaluate the content-type portion of the message header, you would specify it as #[message.inboundProperties['Content-Type']]. Typically, you use message property placeholders with expressions. For more information, see Mule Expression Language MEL.

System Properties

The placeholder value can come from a JDK system property. If you start Mule from the command line, you would specify the properties as follows:


         
      
1
mule -D-M-Dsmtp.username=JSmith -D-M-Dsmtp.password=ChangeMe

or edit the system properties in conf/wrapper.conf if you are deploying Mule as a webapp. When running Mule in a container, as of Mule 2.2.2 you can also specify the server ID in the web.xml file as follows:


         
      
1
2
3
4
<context-param>
  <param-name>mule.serverId</param-name>
  <param-value>MyServer</param-value>
</context-param>

If you start Mule programmatically, you would specify the properties as follows before creating and starting the Mule context:


         
      
1
2
System.getProperties().put("smtp.username", "JSmith");
System.getProperties().put("smtp.password", "ChangeMe");

There are also several system properties that are immutable after startup. To set these, you customize the MuleConfiguration using the set method for the property (such as setId for the system ID), create a MuleContextBuilder, load the configuration to the builder, and then create the context from the builder.

For example:


         
      
1
2
3
4
5
6
7
8
SpringXmlConfigurationBuilder configBuilder = new SpringXmlConfigurationBuilder("my-config.xml");
DefaultMuleConfiguration muleConfig = new DefaultMuleConfiguration();
muleConfig.setId("MY_SERVER_ID");
MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
contextBuilder.setMuleConfiguration(muleConfig);
MuleContextFactory contextFactory = new DefaultMuleContextFactory();
MuleContext muleContext = contextFactory.createMuleContext(configBuilder, contextBuilder);
muleContext.start();

For information on the set methods you can use to set system properties, see org.mule.config.DefaultMuleConfiguration. For information on configuration builders, see About Configuration Builders.

Environment Variables

There are several ways to access environment variables, but there is no standard way.

See Also

  • Read more about mule messages and their properties in our MuleSoft Blog.