Mule ESB:Context Property Placeholder

后端 未结 7 1598
暖寄归人
暖寄归人 2021-02-20 06:48

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



        
相关标签:
7条回答
  • 2021-02-20 07:21

    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.

    0 讨论(0)
  • 2021-02-20 07:24

    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/

    0 讨论(0)
  • 2021-02-20 07:29

    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!

    0 讨论(0)
  • 2021-02-20 07:32

    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"/>
    
    0 讨论(0)
  • 2021-02-20 07:32

    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

    0 讨论(0)
  • 2021-02-20 07:32

    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"

    0 讨论(0)
提交回复
热议问题