properties - Camel 文件uri使用属性

标签 properties apache-camel

我正在尝试使用属性文件从文件夹路由:

我的属性文件有一些属性:
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/

相关文章:

java - Properties.store() - 禁止时间戳注释

c#-4.0 - 如何在 C# 4.0 中创建静态类的属性

java - Apache Camel SNMP 组件

asynchronous - 何时使用 Camel Wiretap 或 SEDA?

apache-camel - 如何将参数传递给 Camel 路线?

asp.net - 如何以声明方式将页面的属性值插入到其呈现中?

ios - 在类方法中设置属性变量

python - 对象属性和类型属性之间的区别

java - 通过 Apache Camel 调用 NTLMv2 安全端点

java - 在 Apache Camel 中将消息拆分为多个(至少两个)