101.5. Spring PropertyPlaceholderConfigurer と File コンポーネントの使用
Camel では、Simple 言語から直接 File 言語を使用することができます。これにより、Spring XML で Content Based Router を簡単に実行できます。ここでは、以下のようにファイルエクステンションに基づいてルーティングすることができます。
File エンドポイントの fileName オプションを使用して File 言語を使用して動的ファイル 名を設定する場合は、
の代替構文(Camel 2.5 以降で利用可能)を使用して Springs PropertyPlaceholderConfigurer との競合を避けるようにしてください。
bundle-context.xml
bundle-context.cfg
fromEndpoint=activemq:queue:test
toEndpoint=file://fileRoute/out?fileName=test-$simple{date:now:yyyyMMdd}.txt
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'
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'