104.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>
Copy to Clipboard Toggle word wrap

如果您使用 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>
Copy to Clipboard Toggle word wrap

bundle-context.cfg

fromEndpoint=activemq:queue:test
toEndpoint=file://fileRoute/out?fileName=test-$simple{date:now:yyyyMMdd}.txt
Copy to Clipboard Toggle word wrap

请注意,我们在上面的 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'
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat