【问题标题】:How to load properties file in Mule ESB 3.9.0 as per the environment?如何根据环境在 Mule ESB 3.9.0 中加载属性文件?
【发布时间】:2019-08-23 10:18:12
【问题描述】:

我正在开发 Mule ESB 3.9.0 社区版。 我必须将 esb 应用程序部署到不同的环境,如 dev、int、prod 等。所以我做了以下事情:

mule-app.properties:
env = dev

并创建了三个属性文件:

esb-frontoffice-dev.config.properties
esb-frontoffice-int.config.properties
esb-frontoffice-prod.config.properties

现在在 ESB 配置文件中,我定义了属性占位符,如下所示:

  <context:property-placeholder location="esb-frontoffice-${env}.config.properties"/>

然后在构建工件之后,我将其部署在 Mule ESB 3.9.0 运行时服务器中。但我收到以下错误:

Caused by: java.io.FileNotFoundException: class path resource [esb-frontoffice-${env}.config.properties] cannot be opened because it does not exist
        at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:150) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:80) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
        ... 36 more

【问题讨论】:

    标签: mule-esb


    【解决方案1】:

    您需要在 MULE_HOME/conf/wrapper.conf 中将 env 定义为 Java 属性。

    例子:

    wrapper.java.additional.23=-Denv=prod
    

    使用文件中以前未用于其他属性的任何数字代替 23。

    【讨论】:

    • 谢谢@aled 这个解决方案效果很好。但是我想理解这一点:当我在服务器上部署应用程序时,mule-app.properties 不起作用,但是当我在 Anypoint Studio 中进行开发和运行流程时它起作用了。为什么会这样?
    • mule-app.properties 与应用程序打包在一起,不能根据环境进行更改。它足以在 Studio 中进行测试。为每个 Mule 服务器设置 Java 属性。
    猜你喜欢
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    相关资源
    最近更新 更多