title: Apache camel - I use Spring XML to define my Camel Context. Is it possible to get the same camelcontext object in Java at runtime?
body: <p>I use Spring XML to define my Camel Context. Is it possible to get the same camelcontext object in Java at runtime? I need this object to add more data and send it to an existing route. I cannot do it in XML and need the object as I will be listening for errors and have to act when the event listener is triggered.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Configures the Camel Context--&gt;
  
     &lt;camelContext id="ovcOutboundCamelContext" 
                   errorHandlerRef="deadLetterErrorHandler" 
                   xmlns="http://camel.apache.org/schema/spring" 
                   useMDCLogging="true"&gt;
  
         &lt;route id="processAuctionMessageRoute"&gt;
              &lt;from uri="direct:processAuctionMessage"/&gt;
              &lt;to uri="bean:CustomerService?method=processAuctionMessage"/&gt;
              &lt;to uri="direct:splitMessage"/&gt;
          &lt;/route&gt;
  
          &lt;route id="splitMessagesRoute"&gt;
          &lt;from uri="direct:splitMessage"/&gt;
          &lt;split parallelProcessing="true" executorServiceRef="auctionsSplitThreadPoolProfile" id="splitId"&gt;
              &lt;simple&gt;${body}&lt;/simple&gt;
              &lt;to uri="bean:CustomerService?method=transformCompanyMessageForAuction"/&gt;
              &lt;to uri="bean:CustomerService?method=processCompanyMessageForAuction"/&gt;
          &lt;/split&gt;
          &lt;to uri="direct:end"/&gt;           
      &lt;/route&gt;
  
      &lt;route id="endProcessor"&gt;
          &lt;from uri="direct:end"/&gt;
          &lt;log loggingLevel="INFO" message="End of route ${threadName}"/&gt;
      &lt;/route&gt;
  &lt;/camelContext&gt;
  </code></pre>
  
  <p>I am trying to get this context with the already existing routes in Java, but it did not work. Please help.</p>
  
  <pre><code>public  void test() throws Exception {      
      CamelContext context = new DefaultCamelContext();
      context.start();
      System.out.println("context:" + context.getRoutes().size());
      context.getRoute("direct:gotoExistingProcess");     
      addRoutesToCamelContext(context);
      System.out.println("context:" + context.getRoutes().size());
      context.stop();
  }
  </code></pre>