我试图获得一个单独的配置/属性文件骆驼相关的东西和其他的东西。使用蓝图,但我想这可能是在这种情况下春天骆驼和指定没有硬编码的属性文件
据我所知,这是在卡拉夫使用配置数据的属性占位符的好习惯。将在../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>
../karaf/ect/org.example.project.cfg文件:
ENDPOINT.IN=C:/Users/username/Documents/project/folderwatch
在camelContext我们ALSE必须使用propertyPlaceholder的可能性。 /Users/username/Documents/project/camel.properties:如果我把它定义这样
...
<propertyPlaceholder id="properties" location="file:C:/Users/username/Documents/project/camel.properties" />
...
并移动到文件C属性的作品。
但是这是我的蓝图文件中的固定路径。我认为最好将它配置为在不同的开发环境中进行测试/工作/ ......只需指向一个不同的配置文件即可。
我想做到这一点,它不工作:
...
<propertyPlaceholder id="properties" location="file:{{CAMEL.PROPERTIES_FILE}}" />
...
../karaf/ect/org.example.project.cfg文件:
CAMEL.PROPERTIES_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,骆驼2.15.3,Win7的
为什么引入第二个配置文件如果y你已经有了蓝图cfg文件?只需将所有属性放在cfg文件中,并在骆驼上下文外部使用'$ {my.property}'并在Camel上下文中使用'{{another.property}}'来获取用cfg文件中的值替换指定的键。 – Ralf