我正在尝试使用属性文件从文件夹路由:
我的属性文件有一些属性:
from.file = D:/开发/资源
我想在 Camel 上下文xml中使用它作为文件路由,
我试过:
<camel:route id="Main-Route">
<camel:from uri="file:${from.file}" />
<camel:to uri="seda:fooQueue" />
</camel:route>
但是 Camel 向我抛出了异常:
不允许使用带有 ${ } 占位符的动态表达式。使用 fileName 选项设置动态表达式。
我怎样才能做到这一点 ?
最佳答案
在 Camel 中,您使用 {{property}} 在您的路由中注入(inject)属性。
请在此处阅读更多信息 http://camel.apache.org/properties.html .
您的示例将更改为:
<camel:route id="Main-Route">
<camel:from uri="file:{{from.file}}" />
<camel:to uri="seda:fooQueue" />
</camel:route>
您还需要告诉 Camel 在哪里可以找到您的属性文件。从上面的链接:
Spring XML 提供了两种配置方式。您可以将 spring bean 定义为 PropertiesComponent,这类似于 Java DSL 中的方式。或者你可以使用标签。
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:com/mycompany/myprop.properties"/>
</bean>
使用标签使配置更加新鲜,例如:
<camelContext ...>
<propertyPlaceholder id="properties" location="com/mycompany/myprop.properties"/>
</camelContext>
关于properties - Camel 文件uri使用属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26448351/