105.5. 将 Spring PropertyPlaceholderConfigurer 与 File 组件一起使用


在 Camel 中,您可以直接从 简单 语言使用文件 语言,在 Spring XML 中更轻松地使用基于内容的路由路由器,其中我们可以根据文件扩展进行路由,如下所示:

<from uri="file://input/orders"/>
   <choice>
     <when>
         <simple>${file:ext} == 'txt'</simple>
         <to uri="bean:orderService?method=handleTextFiles"/>
     </when>
     <when>
         <simple>${file:ext} == 'xml'</simple>
         <to uri="bean:orderService?method=handleXmlFiles"/>
     </when>
     <otherwise>
         <to uri="bean:orderService?method=handleOtherFiles"/>
     </otherwise>
  </choice>

如果您在 File 端点中使用 fileName 选项使用文件语言设置动态文件名,请确保
使用替代语法(来自 Camel 2.5 的提供),以避免使用 Springs PropertyPlaceholderConfigurer 冲突。???

bundle-context.xml

<bean id="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:bundle-context.cfg" />
</bean>

<bean id="sampleRoute" class="SampleRoute">
    <property name="fromEndpoint" value="${fromEndpoint}" />
    <property name="toEndpoint" value="${toEndpoint}" />
</bean>

bundle-context.cfg

fromEndpoint=activemq:queue:test
toEndpoint=file://fileRoute/out?fileName=test-$simple{date:now:yyyyMMdd}.txt

请注意,我们如何在上面的 toEndpoint 中使用 $simple\{ } 语法。
如果没有这样做,Spring 会抛出异常,如下所示

org.springframework.beans.factory.BeanDefinitionStoreException:
Invalid bean definition with name 'sampleRoute' defined in class path resource [bundle-context.xml]:
Could not resolve placeholder 'date:now:yyyyMMdd'
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部