Mule ESB:Context Property Placeholder
Asked Answered
I

7

11

I have a question regarding Mule's context property placeholder, I have two files set up like this:

<context:property-placeholder location="classpath:mule-app-1.properties, file:///etc/mule/conf/mule-app-2.properties" /> 

Firstly is this a valid configuration, secondly which file will take precedence over the other? app1 or app2 file?

-S

Illegalize answered 21/11, 2013 at 19:21 Comment(0)
R
9

Each will be loaded in turn, overwriting duplicate properties from the first one. So in your case, properties defined in mule-app-2.properties will take precedence.

Towards the end of this article I described using this method to provide environment specific configuration properties.

Ricer answered 22/11, 2013 at 13:33 Comment(0)
T
3

Yes, you can have multiple files loaded through Mule context property placeholder. Correct way to do it is to place the properties file in src/main/resources, this folder is in classpath and then specify something like this:

<context:property-placeholder location="mule-app-1.properties, mule-app-2.properties" />

I am not sure why would you want to define duplicate properties in them

EDIT:

To specify order of loading multiple files, use order attribute:

<context:property-placeholder location="mule-app-1.properties" order="1"/>
<context:property-placeholder location="mule-app-2.properties" order="2"/>
Thebes answered 21/11, 2013 at 19:32 Comment(3)
so which file would be loaded first , app-1 or app-2? Do you know which takes precedence?Illegalize
So my question really is if the order attribute is NOT specified, & I have the two properties files setup will that cause an error or is there a default ordering imposed? If so what is the default ordering.Illegalize
I've answered your 1st question and added spring tag for your 2nd question as that is really a spring and not mule question. I would suggest you try putting duplicate values and check yourself the orderingThebes
S
2

Your configuration should be as follows:

 <context:property-placeholder location="mule-app.properties, file:C://Users//schiraboina//Desktop//123.txt"/>

In the above case you are trying to read the values by using '${key_name}'.The order of precedence will be 1. mule-app.properties 2. Read file from external location

Scorn answered 9/12, 2015 at 11:14 Comment(0)
D
0

I have also come across the same scenario. Below is the outcome of my practical experience:

  1. If both files exists either inside project or server, both will be loaded during the project/app startup. In case the files are not available, it will throw exception (java.io.FileNotFoundException : The system cannot find the file specified) while running the application.

  2. It is quite interesting to use multiple properties files and to know the precedence. In this case both property files will be loaded and hence properties defined inside both files will be loaded during the run time. However, mule always gives preference to the lastly declared file in case same properties are defined in both files and additional attribute like order hasn't been defined.

    For Example if there is a property "db.dbname=test_university" declared inside
    "mule-app-1.properties" and "db.dbname=university" inside "mule-app-2.properties" then ${db.dbname} inside config xml will load "university"

Doth answered 11/8, 2015 at 12:5 Comment(0)
S
0

For further information of this question. The data will be read giving first preference for data in CLASSPATH, then the data in the File will be read!

Scorn answered 11/12, 2015 at 5:28 Comment(0)
E
0

Spring will load properties from each resource in turn, overriding properties when it finds them more than once. This allows you to provide default values for properties, and customize them per environment.

For eg:

    <context:property-placeholder 
  location="classpath:myapp-config.properties,classpath:myapp-config-${MULE_ENV}.properties,file:/opt/mule/conf/${MULE_ENV}/myapp-config.properties" 
  ignore-resource-not-found="true" 
  ignore-unresolvable="true" />

This is very similar to what you have mentioned above and to answer your question:

  • Syntax is perfectly fine. No exception will be thrown
  • Mule-app-22.properties will take precedence over mule-app-1.properties.

Refer this link for more details: http://confluex.com/blog/integration-software-is-software/

Enlace answered 5/8, 2016 at 19:6 Comment(0)
S
0

By Tim Hennekey You can use this example for MULE with Spring:

    <spring:bean id="property-placeholderInstance" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" name="Bean">
        <spring:property name="locations">
            <spring:list>
                <spring:value>file:${mule.home}/conf/PropertyFile1.properties</spring:value>
                <spring:value>file:${mule.home}/conf/PropertyFile2.properties</spring:value>
            </spring:list>
        </spring:property>
    </spring:bean>
Sofko answered 22/6, 2017 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.