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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • Externalize Microservice Configuration With Spring Cloud Config
  • A Guide To Build, Test, and Deploy Your First DApp
  • How To Build Web Service Using Spring Boot 2.x
  • Visually Designing Views for Java Web Apps

Trending

  • OTel Me Why: The Case for OpenTelemetry Beyond the Shine
  • BigList: a Scalable High-Performance List for Java
  • Data Governance Essentials: Policies and Procedures (Part 6)
  • Comprehensive Guide to Java String Formatting

Mule: Load Properties as per the Environment (With Default Properties File)

This brief tutorial will show you how to load the properties file automatically as per the environment in a MuleSoft application.

By 
Amit Ghorpade user avatar
Amit Ghorpade
·
Dec. 10, 17 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
29.0K Views

Join the DZone community and get the full member experience.

Join For Free

It has been a best practice to load the properties file as per the environment, instead of some manual copy/paste or other techniques to do it.

Today, I will walk you through a MuleSoft application which uses the properties file as per the environment. When you wan to the run application in a dev runtime/environment, your application should pick up the dev environment properties file. Also, sometimes there is a requirement that we should have a common/default properties file which will hold common properties for all environments.

Steps

You can download the sample code from GitHub.

You can create a sample hello world application using the below steps:

Open Anypoint Studio -> file -> new -> MuleSoft project.Image title

Give the project name "helloworld" and click on finish.

The project structure will look like this:Image title

Create an HTTP endpoint, drag and drop the HTTP component, and configure it as shown below:Image title

Once the HTTP component is set, add set payload component and provide the below payload:

 ${hello} ${test} 

The hello and test key will be filled by the properties file value.

Add the dev.properties file to the src/main/resources folder as below:Image title

Add properties key=value in the dev.properties file, which will be picked up by set payload component at runtime.

Run the application with the argument as  -Dmule.env=dev . This will run the application as it is running in the development environment and will pick up the dev.properties file.

Once the application is deployed successfully, (check the console if the application deployed properly or not), go to the browser  and hit http://localhost:9090/. It will give you the response "hello."

Now I have a requirement that the test key is common to all environments and should be defaulted to default/common properties file.

Add the my-dev.properties file with the below content:

hello=local hello
test=local test

Add the below configuration in the helloworld.xml file for the load default property file as well as the environment specific properties file (remove if any Spring bean property placeholder configuration is available):

<spring:beans>
<context:property-placeholder
location="classpath:my-dev.properties,
classpath:${mule.env}.properties" />
</spring:beans>

Run the application with a dev environment:

Image title

Once the application is deployed, hit http://localhost:9090/ in the browser and you will see that the test key value is coming from a common file while hello world is overriden and coming from the dev.properties file.

References:

https://docs.mulesoft.com/mule-user-guide/v/3.6/deploying-to-multiple-environments

https://docs.mulesoft.com/mule-user-guide/v/3.5/using-parameters-in-your-configuration-files

Property (programming) application

Opinions expressed by DZone contributors are their own.

Related

  • Externalize Microservice Configuration With Spring Cloud Config
  • A Guide To Build, Test, and Deploy Your First DApp
  • How To Build Web Service Using Spring Boot 2.x
  • Visually Designing Views for Java Web Apps

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: