264.7. 在位置中使用系统和环境变量
从 Camel 2.7 开始提供
该位置现在支持将占位符用于 JVM 系统属性和 OS 环境变量。
例如:
location=file:${karaf.home}/etc/foo.properties
location=file:${karaf.home}/etc/foo.properties
在上面的位置,我们使用带有键 karaf.home 的 JVM 系统属性来定义使用文件方案的位置。
要使用 OS 环境变量,您必须用 env 前缀:
location=file:${env:APP_HOME}/etc/foo.properties
location=file:${env:APP_HOME}/etc/foo.properties
其中 APP_HOME 是 OS 环境。
您可以在同一位置有多个占位符,例如:
location=file:${env:APP_HOME}/etc/${prop.name}.properties
location=file:${env:APP_HOME}/etc/${prop.name}.properties
ip=== 使用系统和环境变量来配置属性前缀和后缀
从 Camel 2.12.5, 2.13.3, 2.14.0 开始提供
propertyPrefix,propertySuffix 配置属性支持使用 JVM 系统属性和 OS 环境变量的占位符。
例如,如果 PropertiesComponent 配置了以下属性文件:
dev.endpoint = result1 test.endpoint = result2
dev.endpoint = result1
test.endpoint = result2
然后,使用以下路由定义:
可以通过将系统属性 阶段 更改为 dev 来更改目标端点(消息将路由到 mock:result1)或 test (消息将路由到 mock:result2)。