Accessing mule-app.properties in custom properties file located in src/main/resources on cloudhub

匆匆过客 提交于 2019-12-11 13:37:29

问题


I have a mule application built using mule apikit. The mule-app.properties file contains below property:

orig.db.url=jdbc:db2://mmrs001.nmd.net:1004/dudu:user=abc43;password=xxxx;

The custom properties file src/main/resources/dev.properties contains below property:

db.url=${orig.db.url}

And, the mule configuration xml file contains below property-placeholder:

<context:property-placeholder location="dev.properties"/>

Now, when I deploy it locally everything works fine and I am able to run the flow. But, at the same time when I deploy on Cloudhub it gives me below exception:

Invalid bean definition with name 'get:/total_amount:total_amount-db-config' defined in null: Could not resolve placeholder 'orig.db.url' in string value "jdbc:db2://mmrs001.nmd.net:1004/dudu:user=abc43;password=xxxx;"

I am unable to understand what am I missing here?


回答1:


How did you deploy to CloudHub? If you used the deployment tool from Anypoint Studio you have an option to set properties before deployment.




回答2:


The mule-app.properties will get added to system properties instead of classpath properties. We can't refer to system properties from property files added to classpath. We need to move these properties to classpath to resolve these in runtime.

One way to override this behaviour by importing mule-app.properties using:

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

It tells spring to load properties in respective order. So, first mule-app.properties gets loaded and then dev.properties.

But, its not the best practice to include the mule-app.properties file in the classpath. Best way is to remove the dev properties from mule-app.properties and put it inside dev.properties.




回答3:


By default when deploying to cloudhub all properties from the mule-app.properties should appear in the properties tab. Did you not see them when you deployed the first time?



来源:https://stackoverflow.com/questions/34141515/accessing-mule-app-properties-in-custom-properties-file-located-in-src-main-reso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!