gpt4 book ai didi

java - Mule PlaceHolder 文档有误吗?

转载 作者:行者123 更新时间:2023-11-30 06:53:05 24 4
gpt4 key购买 nike

我一直在寻找使用正确的属性方式在多个环境中部署......但该示例不起作用:网址:https://docs.mulesoft.com/mule-user-guide/v/3.8/deploying-to-multiple-environments

我创建了一个项目,配置了 http,如示例中所示:

<http:listener-config name="HttpListenerConfiguration"
doc:name="HTTP Listener Configuration"
host="${mule.env.host}"
port="${mule.env.port}"
basePath="${mule.env.basePath}" />

他们说的

This example uses Spring’s property placeholder resolution mechanism. The variable bits are clearly visible: the base path, host, and port can vary for each environment where this connector gets deployed in. When deploying your application, mule.env can be dynamically replaced by the particular environment you’re deploying to, such as qa or prod.

我在 java/main/resources 中创建了一个名为 config.properties 的文件:

dev.basePath=test/products
dev.host=localhost
dev.port=8082
prod.basePath=products
prod.host=www.acme.com
prod.port=8081

并设置占位符:

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

我的 mule-app.properties:

mule.env=dev

当我在 AS 中运行它时:

[Could not resolve placeholder 'mule.env.host' in string value "<http:listener-config name="ejemplop....]

如果我更改值:

 ${mule.env.host} to ${${mule.env}.host} 

并且主机属性有效,但如果我对端口执行相同的操作

(${${mule.env}.port} 

给我一​​个错误

[..${${mule.env}.port}' is not a valid value of union type 'substitutableInt'....]

但是如果我添加到我的属性文件

env.port=${${mule.env}.port}

并将连接器更改为:

<http:listener-config name="HttpListenerConfiguration"
doc:name="HTTP Listener Configuration"
host="${${mule.env}.host}"
port="${env.port}"
basePath="${mule.env.basePath}" />

这是有效的。有一种奇特的或正确的方法来做到这一点吗?

最佳答案

CHo,您正朝着多环境方向前进,但还没有完全实现。如果您需要多个属性文件,每个文件都具有相同名称但特定于环境的值的相同属性,我会建议您这样做。

在您的应用程序中,您将拥有类似以下内容:

<context:property-placeholder location="config_${mule.env}.properties"/>

然后在您的流程中您将拥有:

<http:listener-config name="HttpListenerConfiguration"
doc:name="HTTP Listener Configuration"
host="${host}"
port="${port}"
basePath="${basePath}" />

然后您将拥有一个名为 config_dev.properties 的属性文件,其中包含:

basePath=test/products
host=localhost
port=8082

您将拥有另一个名为 config_prod.properties 的属性文件,其中包含:

basePath=products
host=www.acme.com
port=8081

当 mule.env 设置为 dev 时,将使用 config_dev 值。当设置为 prod 时,将使用 config_prod 值。

关于java - Mule PlaceHolder 文档有误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42369762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com