Mule ESB:Context Property Placeholder

2020-07-05 05:25发布

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

标签: spring mule esb
7条回答
叼着烟拽天下
2楼-- · 2020-07-05 05:47

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"

查看更多
可以哭但决不认输i
3楼-- · 2020-07-05 05:56

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/

查看更多
Rolldiameter
4楼-- · 2020-07-05 05:57

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"/>
查看更多
Animai°情兽
5楼-- · 2020-07-05 06:04

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!

查看更多
劳资没心,怎么记你
6楼-- · 2020-07-05 06:09

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.

查看更多
成全新的幸福
7楼-- · 2020-07-05 06:11

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>
查看更多
登录 后发表回答