105.5. Spring PropertyPlaceholderConfigurer を File コンポーネントと一緒に使用する


Camel では、Simple 言語から ファイル言語 を直接使用できます。これにより、以下に示すように、ファイル拡張子に基づいてルーティングできる Spring XML でコンテンツベースのルーターを簡単に実行できます。

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

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

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

上記の toEndpoint で $simple\{ } 構文を使用する方法に注意してください。
これを行わないと、衝突が発生し、Spring は次のような例外を出力します。

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

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat, Inc.