title: Spring Boot Apache Camel Routes testing
body: <p>I have a Springboot application, where I have some Camel routes configured.</p>
  <pre class="lang-java prettyprint-override"><code>public class CamelConfig {
      private static final Logger LOG = LoggerFactory.getLogger(CamelConfig.class);
  
      @Value(&quot;${activemq.broker.url:tcp://localhost:61616}&quot;)
      String brokerUrl;
  
      @Value(&quot;${activemq.broker.maxconnections:1}&quot;)
      int maxConnections;
  
      @Bean
      ConnectionFactory jmsConnectionFactory() {
          PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(new ActiveMQConnectionFactory(brokerUrl));
          pooledConnectionFactory.setMaxConnections(maxConnections);
          return pooledConnectionFactory;
      }
  
      @Bean
      public RoutesBuilder route() {
          LOG.info(&quot;Initializing camel routes......................&quot;);
          return new SpringRouteBuilder() {
              @Override
              public void configure() throws Exception {
                  from(&quot;activemq:testQueue&quot;)
                    .to(&quot;bean:queueEventHandler?method=handleQueueEvent&quot;);
              }
          };
      }
  }
  </code></pre>
  <p>I want to test this route from <code>activemq:testQueue</code> to <code>queueEventHandler::handleQueueEvent</code>.
  I tried different things mentioned here <a href="http://camel.apache.org/camel-test.html" rel="nofollow noreferrer">http://camel.apache.org/camel-test.html</a>, but doesn't seem to get it working.</p>
  <p>I am trying to do something like this:</p>
  <pre class="lang-java prettyprint-override"><code>    @RunWith(SpringRunner.class)
      @SpringBootTest(classes = {CamelConfig.class,   CamelTestContextBootstrapper.class})
      public class CamelRouteConfigTest {
  
      @Produce(uri = &quot;activemq:testQueue&quot;)
      protected ProducerTemplate template;
  
      @Test
      public void testSendMatchingMessage() throws Exception {
          template.sendBodyAndHeader(&quot;testJson&quot;, &quot;foo&quot;, &quot;bar&quot;);
          // Verify handleQueueEvent(...) method is called on bean queueEventHandler by mocking
      }
  </code></pre>
  <p>But my ProducerTemplate is always <code>null</code>. I tried auto-wiring <code>CamelContext</code>, for which I get an exception saying <em>it cannot resolve camelContext</em>. But that can be resolved by adding <code>SpringCamelContext.class</code> to <code>@SpringBootTest</code> classes. But my <code>ProducerTemplate</code> is still <code>null</code>.</p>
  <p>Please suggest. I am using Camel 2.18 and Spring Boot 1.4.</p>