Read and use properties file in Mule 4

I have guided you how to read and use a properties file in Mule 3, in Mule 4, this operation will be different because reading and using properties files in Mule 4 will no longer relate to Spring framework anymore. How is it in details? Let’s find out in this tutorial, guys!

First, I created a new Mule project using Anypoint Studio 7 with Mule 4 as an example:

Read and use properties file in Mule 4

I also created a simple application with HTTP Listener Connector and Logger Component as follows:

Read and use properties file in Mule 4

Inside:

HTTP Listener Connector is configured as follows:

Read and use properties file in Mule 4

Global Configuration:

Read and use properties file in Mule 4

Logger Component is configured as follows:

Read and use properties file in Mule 4

Now I will also define a properties file located in the src/main/resource directory named application.properties with the following simple content:

To read the application.properties file and use the author.name property in Mule 4, we need to do the following steps:

First, you need to configure Global Configuration properties by opening the mule-esb-properties-file-mule4.xml file, selecting the Global Elements tab,

Read and use properties file in Mule 4

Click Create button and select Configuration properties as follows:

Read and use properties file in Mule 4

Result:

Read and use properties file in Mule 4

Click the Browse button to select the application.properties file, the results are as follows:

Read and use properties file in Mule 4

OK, now you can press the OK button to close this window.

To use author.name property in Logger Component, you can declare with the placeholder as follows:

The result when running the application and the request to the URL http://localhost:8081/properties-file will be as follows:

Read and use properties file in Mule 4

To use many properties files, you need to declare each properties file with a Global Configuration properties. Examples are as follows:

Mule 4 does not support ignore-resource-not-found features like Mule 3 with Spring framework!

Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment