Spring Camel并指定属性文件,而不进行硬编码

Spring Camel并指定属性文件,而不进行硬编码,spring,apache-camel,karaf,blueprint,Spring,Apache Camel,Karaf,Blueprint,我试图为骆驼相关的东西和其他东西获取一个单独的配置/属性文件。使用Blueprint,但我想在这种特殊情况下,也可能是Spring 据我所知,在Karaf中,为配置数据使用属性占位符是一种很好的做法。将在../karaf/ect文件夹中搜索 很好,因为我们没有固定的编码路径。我让那个部分工作 <blueprint ... <cm:property-placeholder persistent-id="org.example.project" update-strategy="

我试图为骆驼相关的东西和其他东西获取一个单独的配置/属性文件。使用Blueprint,但我想在这种特殊情况下,也可能是Spring

据我所知,在Karaf中,为配置数据使用属性占位符是一种很好的做法。将在../karaf/ect文件夹中搜索

很好,因为我们没有固定的编码路径。我让那个部分工作

<blueprint ...
    <cm:property-placeholder persistent-id="org.example.project" update-strategy="reload" id="prop">
        ...
    </cm:property-placeholder>

    <camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="watchfolder">
            <from uri="file:{{ENDPOINT.IN}}"/>
            <to uri="direct:test"/>
        </route>
在这种情况下,我们也可以使用propertyPlaceholder。如果我这样定义它,它就会起作用

...
            <propertyPlaceholder id="properties" location="file:C:/Users/username/Documents/project/camel.properties" />
...
结果是:

..
Caused by: java.io.FileNotFoundException: {{CAMEL.PROPERTIES_FILE}} (The system cannot find the file specified)
..
该值似乎没有被解析为属性。 我试过这样的变化:

location="file:${CAMEL.PROPERTIES_FILE}" 
location="file:{{blueprint:CAMEL.PROPERTIES_FILE}}" 
location="file:{{blueprint:prop:CAMEL.PROPERTIES_FILE}}" 
(最后的这些尝试只是赌博。我不理解该功能背后的含义)

因此,最终的问题是:

如何指定可变骆驼属性文件?


我使用的是:Karaf 4.0.0、Camel 2.15.3、Win7

有两种方法可以做到这一点

<propertyPlaceholder id="properties" location="${env:PROP_FILE_OS_ENV_LOC}"/>

其中,PROP_FILE_OS_ENV_LOC是一个OS环境变量

<propertyPlaceholder id="properties" location="${PROP_FILE_JVM_LOC}"/>


其中PROP_FILE_JVM_LOC是一个JVM属性

如果已经有blueprint cfg文件,为什么还要引入第二个配置文件?只需将所有属性放在cfg文件中,并在camel上下文外部使用
${my.property}
,在camel上下文内部使用
{{other.property}}
,即可将指定的键替换为cfg文件中的值。
location="file:${CAMEL.PROPERTIES_FILE}" 
location="file:{{blueprint:CAMEL.PROPERTIES_FILE}}" 
location="file:{{blueprint:prop:CAMEL.PROPERTIES_FILE}}" 
<propertyPlaceholder id="properties" location="${env:PROP_FILE_OS_ENV_LOC}"/>
<propertyPlaceholder id="properties" location="${PROP_FILE_JVM_LOC}"/>