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:

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

Inside:
HTTP Listener Connector is configured as follows:

Global Configuration:

Logger Component is configured as follows:

Now I will also define a properties file located in the src/main/resource directory named application.properties with the following simple content:
|
1 |
author.name=Khanh |
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,

Click Create button and select Configuration properties as follows:

Result:

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

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:
|
1 |
<logger level="INFO" doc:name="Logger" doc:id="28bb6f13-0c18-4424-b3c8-15e1841a8bac" message="Hello ${author.name}" category="com.huongdanjava"/> |
The result when running the application and the request to the URL http://localhost:8081/properties-file will be as follows:

To use many properties files, you need to declare each properties file with a Global Configuration properties. Examples are as follows:
|
1 2 |
<configuration-properties doc:name="Configuration properties" doc:id="4a48b0e5-7ebd-449d-9c29-4cfa78e6e469" file="application.properties" /> <configuration-properties doc:name="Configuration properties" doc:id="4a48b0e5-7ebd-449d-9c29-4cfa78e6e462" file="application2.properties" /> |
Mule 4 does not support ignore-resource-not-found features like Mule 3 with Spring framework!
