DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache
  • Modify JSON Data in Postgres and Hibernate 6
  • Top 10 C# Keywords and Features

Trending

  • What Is Plagiarism? How to Avoid It and Cite Sources
  • Engineering LLMOps: Building Robust CI/CD Pipelines for LLM Applications on Google Cloud
  • Building an Image Classification Pipeline With Apache Camel and Deep Java Library (DJL)
  • Master-Class: Understanding Database Replication (Single, Multi, and Leaderless)

Property Files in Mule 4

It's best practice to centralize the management of properties than hard code values at the location of use. This allows for the reuse of values and better maintenance.

By 
Alex Theedom user avatar
Alex Theedom
·
Mar. 21, 21 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
16.5K Views

Join the DZone community and get the full member experience.

Join For Free

Main Points:

  • Property files allow the centralization of properties.
  • Property placeholders used instead of hard coding.
  • Property file location must be configured in global elements.
  • Property files can be constructed in Java or YAML format.

Centralization of Application Properties

It is best practice to centralize the management of properties rather than hard code values at the location of use. This allows for the reuse of values and better maintenance. Instead of changing the property in multiple places (if the value has been hardcoded), you change the value once in the property file and every location where that property placeholder is used gets to use the new value at runtime.

Setting up A Property File

There are three parts to set up when you want to use property files:

  1. The property file in which the properties are defined.
  2. The Configuration Property in the application's global elements.
  3. The use of the property placeholders in the application configuration.

The Property File

The property file is a text file that contains the key/value pair representing the property value and its property placeholder name. The file can be either a Java property format file or a YAML file format.

Figure 1: Java-style property file format.

db.host=db.examples.com 
db.port=3306 
db.user=admin 
db.password=Password123 
db.database=products


Figure 2: YAML-style property fie format.

db:
  host: db.examples.com
  port: "3306"
  user: admin
  password: Password123
  database: products


Java-style property files have the .properties extend while the YAML-style property files have the .yaml file extension. The two formats in figures 1 and 2 defined the same properties. 

The Property File Location

The property files should be located on the classpath. Typically application property files are located in the src/main/resources directory. 

Provide a Configuration Property Setting

The Mule application must be configured with the location of the property file. This is done by providing its location in the Configuration Property configuration element in the global elements of the application. If the property file is call properties.yaml and is located on the classpath in the src/main/resources directory the configuration of the Configuration Property element looks like figure 3.

Figure 3: Configuration Property set with the location of the property file

The Use of The Property Placeholders

Properties are used by referencing the name of the property enclosed in ${}. For example, the use of the properties set in figures 1 & 2 would look like this ${db.host}, ${db.port}, ${db.user}, ${db.password}, ${db.database} and be used as shown in figure 4.

Figure 4: Using property placeholders in the configuration of a Database connector

It is also possible to reference Mule application properties using the Data Weave function Mule::p. 

Secure and Encrypted Properties

Typically, Mule applications require the use of secure properties such as passwords. These can be encrypted with an encryption key and used in the same way as insecure properties, they can also be hidden from view in CloudHub. 

Property (programming)

Published at DZone with permission of Alex Theedom. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache
  • Modify JSON Data in Postgres and Hibernate 6
  • Top 10 C# Keywords and Features

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook