title: How do I load a Camel Property into a Bean?
body: <p>I have been reading the following page on Camel properties: <a href="http://camel.apache.org/using-propertyplaceholder.html" rel="nofollow noreferrer">http://camel.apache.org/using-propertyplaceholder.html</a>  and also reading the book "Camel In Action".</p>
  
  <p>I found Chapter 6 of "Camel In Action" very helpful in defining Camel properties, and I can load the following three properties from my config.properties:</p>
  
  <pre><code>config.timeout=10000
  config.numSamples=1000
  config.defaultViz=a
  </code></pre>
  
  <p>When I run my Java code I'm able to see the following three values inside my camel route in my applicationContext.xml, as shown in the thread#0 messages below:</p>
  
  <pre><code>14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO  route1  - printing values read from config.properties file
  14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO  route1  - config.timeout= 10000
  14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO  route1  - config.numSamples= 1000
  14670 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO  route1  - config.defaultViz= a
  </code></pre>
  
  <p>However, when I try to pass the variable {{config.defaultViz}} to a String called defaultViz in my SensorGenerator Java class, and print that string I get "{{config.defaultViz}}" on the console instead of the value contained within {{config.defaultViz}}.</p>
  
  <p>In other words, here's what I see on the screen:</p>
  
  <pre><code>Returning List
  defaultViz= {{config.defaultViz}}
  </code></pre>
  
  <p>But I really want to see this on the screen:</p>
  
  <pre><code>Returning List
  defaultViz=a
  </code></pre>
  
  <p>So what am I doing wrong in my applicationContext.xml?</p>
  
  <p>UPDATED: The issue was that I needed to add a Bridge between Spring and Camel as outlined in the link I referenced above.</p>
  
  <p>Here's my UPDATED applicationContext.xml with the bridge:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:camel="http://camel.apache.org/schema/spring"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/util     http://www.springframework.org/schema/util/spring-util-3.0.xsd
          http://camel.apache.org/schema/spring     http://camel.apache.org/schema/spring/camel-spring.xsd
          http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;bean
              class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" /&gt;
      &lt;context:component-scan base-package="com.data.world2" /&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;camel:camelContext id="HelloWorldContext"&gt;
  
  &lt;!--        Add Jackson library to render Java Map into JSON --&gt;
          &lt;camel:dataFormats&gt;
            &lt;camel:json id="jack" library="Jackson"/&gt;
          &lt;/camel:dataFormats&gt;
  
          &lt;camel:route&gt;
              &lt;!-- sends a request to the hello world JMS queue every 10 seconds --&gt;
              &lt;camel:from
                  uri="timer://hello.world.request.timer?fixedRate=true&amp;amp;period={{config.timeout}}" /&gt;
              &lt;camel:to uri="log:hello.world.request?level=INFO&amp;amp;showAll=true" /&gt;
              &lt;camel:bean ref="helloWorld" /&gt;
  
              &lt;!-- now print out the map in JSON format --&gt;
              &lt;camel:marshal ref ="jack"/&gt;
              &lt;camel:convertBodyTo type="java.lang.String" /&gt;
              &lt;camel:log message="${body}"/&gt; 
  
              &lt;!-- print out values read from config.properties file --&gt;
              &lt;camel:log message="printing values read from config.properties file"/&gt;
              &lt;camel:log message="config.timeout= {{config.timeout}}"/&gt; 
              &lt;camel:log message="config.numSamples= {{config.numSamples}}"/&gt;
              &lt;camel:log message="config.defaultViz= {{config.defaultViz}}"/&gt;
  
              &lt;!-- now log the message --&gt;
              &lt;camel:to uri="log:hello.world.response?level=INFO&amp;amp;showAll=true" /&gt;
  
          &lt;/camel:route&gt;
  
      &lt;/camel:camelContext&gt;
  
  &lt;!-- creates a java.util.Properties instance with values loaded from the supplied location --&gt;
  &lt;util:properties id="sensorProperties" location="classpath:/sensor.properties"/&gt;
  
      &lt;!--  pass in sensor.properties and defaultViz from config.properties --&gt;
      &lt;bean class="com.data.world2.SensorGenerator"&gt;
          &lt;property name="sourceProperties" ref="sensorProperties" /&gt;
          &lt;property name="defaultViz" value="${config.defaultViz}"/&gt;
      &lt;/bean&gt;
  
  &lt;!-- declare a Spring bean to use the Camel Properties component in Spring XML --&gt;
      &lt;bean id="properties"
            class="org.apache.camel.component.properties.PropertiesComponent"&gt;
          &lt;property name="location" value="classpath:config.properties"/&gt;
      &lt;/bean&gt;
  &lt;!-- bridge spring property placeholder with Camel --&gt;
  &lt;!-- you must NOT use the &lt;context:property-placeholder at the same time, only this bridge bean --&gt;
      &lt;bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer"&gt;
        &lt;property name="location" value="classpath:config.properties"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>I found this question that is similar but not quite the same: <a href="https://stackoverflow.com/questions/8028679/injecting-property-into-bean">Injecting property into bean</a></p>