camel属性占位符环境特定文件



我使用的是apachecamel 2.15.1,我有三个属性文件,它们在类路径中是特定于环境的,比如myprop.properties, myprop-enva.properties, myprop-envb.properties.我在camelcontext中使用propertyplaceholder,我可以加载我的prop.properties。

当websphereenv.prop=_enva时,我不知道如何加载myprop-enva.properties

我当前的配置如下。。

    <propertyPlaceholder location="classpath:myprop.properties" //Here I need to modify to make it work
        id="placeholder1" />

我尝试更改为location="classpath:myprop${env.prop}.properties",但没有成功。

您可以使用蓝图属性占位符,然后将从服务器加载特定于环境的cfg文件。不同的服务器-不同的cfg文件。

或者,您可以在包阶段(使用maven概要文件)将特定的属性文件放入捆绑包中。

<profiles>
    <profile>
        <id>production</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <properties>
            <env>production</env>
        </properties>
    </profile>
    <profile>
        <id>developer</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <env>developer</env>
        </properties>
    </profile>
</profiles>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>props/**/*.properties</exclude>
            </excludes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources/props/${env}</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    ..........
</build>

您可以添加属性文件的所有位置,并添加忽略选项,然后Camel将跳过不存在的文件。在该位置,您可以引用ENV名称。

查看Camel文档中的更多详细信息

  • http://camel.apache.org/using-propertyplaceholder.html

最新更新