Camel uri file using property

I am trying to use a properties file to route from a folder:

My properties file has a property: from.file = D: / Develop / resources

and I want to use it in camel xml context as file routing,

I tried:

<camel:route id="Main-Route">
        <camel:from uri="file:${from.file}" />
        <camel:to uri="seda:fooQueue" />
</camel:route>

      

But camel throws me an exception: Dynamic expressions with $ {} placeholders are not allowed. Use the fileName parameter to set a dynamic expression.

How can i do this?

+3


source to share


3 answers


In Camel, you use {{property}} to inject properties into your routes. Read more here http://camel.apache.org/properties.html .

Your example will change to:

<camel:route id="Main-Route">
        <camel:from uri="file:{{from.file}}" />
        <camel:to uri="seda:fooQueue" />
</camel:route>

      

You also need to tell Camel where it can find your properties file. From the link above: Spring XML offers two configuration options. You can define a spring bean as a PropertiesComponent, which resembles the way that Java DSL does. Or you can use a tag.



<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
    <property name="location" value="classpath:com/mycompany/myprop.properties"/>
</bean>

      

Using a tag makes the configuration a little fresher, for example:

<camelContext ...>
   <propertyPlaceholder id="properties" location="com/mycompany/myprop.properties"/>
</camelContext>

      

+5


source


In apache camel file component, the source directory must not contain dynamic expressions. If you want to provide a dynamic start directory as well, you can set the entire path to the CamelFileName header of the file component from the properties file using fileComponent defined as<to uri="file://">



+1


source


the problem is that to read the place holder like:

$ {some-property} for some bean for example:

<bean id="bean" class="">
  <property name="field Constructor" value="${some.property}" />
</bean>

      

I get an error.

Solved it by specifying PropertyPlaceholderConfigurer as well:

<bean id="proprty" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <value>file:/D:/Proj/resources/myprop.properties
    </value>
 </bean>

 <bean id="beanId" class="com.viewlinks.eim.properties.MyBean">
    <property name="fieldConstructor" value="${some.property}" />
</bean>


<camel:camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">   

 <propertyPlaceholder id="properties"  location="file:/D:/Proj/resources/myprop.properties"/>

<camel:route id="Main-Route">
  <camel:from uri="file:{{from.file}}" />
  <camel:to uri="file:{{to.file}}" />
</camel:route>

</camel:camelContext>

      

0


source







All Articles