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>
파일 끝점에서 fileName 옵션을 사용하여 파일 언어를 사용하여 동적 파일 이름을 설정한 경우,
에서 대체 구문( Camel 2.5 onwards에서 사용 가능)을 사용하여 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\{ } 구문을 사용하는 방법을 확인하십시오.
이렇게 하지 않으면 clash가 있고 Spring은 다음과 같은 예외를 throw합니다.
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'