问题
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
回答1:
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.
回答2:
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"/>
回答3:
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
回答4:
I have also come across the same scenario. Below is the outcome of my practical experience:
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.
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"
回答5:
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:
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/
回答7:
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>
来源:https://stackoverflow.com/questions/20130038/mule-esbcontext-property-placeholder