在 Apache Camel XML 中指定可选环境 属性

Specify an optional environment property in Apache Camel XML

我在 Apache Camel 中使用了一个可选的环境变量,在某些情况下该值不会存在,但我仍然希望我的配置能够正常工作,假设未找到的环境变量为空。

camelContext id="inboud" xmlns="http://camel.apache.org/schema/spring">
    <!-- and then let Camel use those @Component scanned route builders -->
    <propertyPlaceholder id="properties"
        location="properties/app${env}.properties" ignoreMissingLocation="true" />

    <!-- Messages placed here will be raw data from force.com-->
    <template id="frceProducerTemplate" />

这里的 ${env} 我想设为可选,如果它不存在,则必须将位置设为 properties/app.properties.

有人知道吗?

如果没有 ENV 变量,则不支持默认值。您可以在此处阅读有关使用 属性 占位符的更多信息:http://camel.apache.org/using-propertyplaceholder.html

但是您可以添加 2 个位置,一个带有 ENV,另一个没有 ENV。然后打开 ignoreMissingLocation="true" 然后如果 ENV 不存在,Camel 将忽略它。