264.7. 在位置中使用系统和环境变量
从 Camel 2.7 开始提供
该位置现在支持将占位符用于 JVM 系统属性和操作系统环境变量。
例如:
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
是操作系统环境。
您可以在同一位置上有多个占位符,例如:
location=file:${env:APP_HOME}/etc/${prop.name}.properties
location=file:${env:APP_HOME}/etc/${prop.name}.properties
#=== 使用系统和环境变量配置属性前缀和后缀
从 Camel 2.12.5, 2.13.3, 2.14.0 开始提供
propertyPrefix
,propertySuffix
配置属性支持使用占位符进行 JVM 系统属性和操作系统环境变量。
例如,如果 PropertiesComponent
配置了以下属性文件:
dev.endpoint = result1 test.endpoint = result2
dev.endpoint = result1
test.endpoint = result2
然后,使用以下路由定义:
通过将系统属性 stage
更改为 dev
(消息将路由到 mock:result1
)或 test
(消息将路由到 mock:result2
)来更改目标端点。