263.7. 在位置中使用系统和环境变量

可作为 Camel 2.7 提供

该位置现在支持对 JVM 系统属性和 OS 环境变量使用占位符。

例如:

location=file:${karaf.home}/etc/foo.properties

在以上位置上,我们将 JVM 系统属性与 key karaf.home 使用文件方案来定义位置。

要使用 OS 环境变量,而您必须带有 env 的前缀:

location=file:${env:APP_HOME}/etc/foo.properties

其中 APP_HOME 是 OS 环境。

您可以在同一位置上有多个占位符,例如:

location=file:${env:APP_HOME}/etc/${prop.name}.properties

#=== 使用系统和环境变量配置属性前缀和后缀

可作为 Camel 2.12.5、2.13.3、2.14.0 提供

属性前缀属性Suffix 配置属性支持将占位符用于 JVM 系统属性和 OS 环境变量。

例如:如果使用以下属性文件配置了 PropertiesComponent

dev.endpoint = result1
test.endpoint = result2

然后,使用以下路由定义:

PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
pc.setPropertyPrefix("${stage}.");
// ...
context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
        from("direct:start").to("properties:mock:{{endpoint}}");
    }
});

通过将系统属性 暂存更改 为 dev (消息将路由到 mock:result 1)或 test (消息将路由到 mock:result2),可以更改目标端点。