camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Spring
Date Tue, 15 Jun 2010 13:07:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Spring">Spring</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{warning} <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{info:title=Will
ignore already instantiated classes} <br>The &lt;package&gt; and &lt;packageScan&gt;
will skip any classes which has already been created by Spring etc. So if you define a route
builder as a spring bean tag then that class will be skipped. You can include those beans
using {{&lt;routeBuilder ref=&quot;theBeanId&quot;/&gt;}} or the {{&lt;contextScan/&gt;}}
feature. <br>{info} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h4. Using &lt;packageScan&gt;
<br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >\*\*.??cluded\* would match org.simple.IncludedRoute,
org.simple.Excluded but not match org.simple.PrecludedRoute <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h4.
Using contextScan <br>*Available as of Camel 2.4* <br> <br>You can allow
Camel to scan the container context, e.g. the Spring {{ApplicationContext}} for route builder
instances. This allow you to use the Spring {{&lt;component-scan&gt;}} feature and
have Camel pickup any RouteBuilder instances which was created by Spring in its scan process.
<br> <br>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/contextscan/SpringRouteIsComponentAnnotatedTest.xml}
<br> <br>This allows you to just annotate your routes using the Spring {{@Component}}
and have those routes included by Camel <br>{code} <br>@Component <br>public
class MyRoute extends SpringRouteBuilder { <br> <br>    @Override <br> 
  public void configure() throws Exception { <br>        from(&quot;direct:start&quot;).to(&quot;mock:result&quot;);
<br>    } <br>} <br>{code} <br> <br>You can also use the ANT
style for inclusion and exclusion, as mentioned above in the {{&lt;packageScan&gt;}}
documentation. <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h4. Test time exclusion.  <br>
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Spring-SpringSupport"></a>Spring Support</h2>

<p>Apache Camel is designed to work nicely with the <a href="http://www.springframework.org/"
class="external-link" rel="nofollow">Spring Framework</a> in a number of ways.</p>
<ul>
	<li>Camel uses Spring Transactions as the default transaction handling in components
like <a href="/confluence/display/CAMEL/JMS" title="JMS">JMS</a> and <a href="/confluence/display/CAMEL/JPA"
title="JPA">JPA</a></li>
	<li>Camel works with Spring 2 XML processing with the <a href="/confluence/display/CAMEL/Xml+Configuration"
title="Xml Configuration">Xml Configuration</a></li>
	<li>Camel Spring XML Schema's is defined at <a href="/confluence/display/CAMEL/Xml+Reference"
title="Xml Reference">Xml Reference</a></li>
	<li>Camel supports a powerful version of <a href="/confluence/display/CAMEL/Spring+Remoting"
title="Spring Remoting">Spring Remoting</a> which can use powerful routing between
the client and server side along with using all of the available <a href="/confluence/display/CAMEL/Components"
title="Components">Components</a> for the transport</li>
	<li>Camel provides powerful <a href="/confluence/display/CAMEL/Bean+Integration"
title="Bean Integration">Bean Integration</a> with any bean defined in a Spring ApplicationContext</li>
	<li>Camel integrates with various Spring helper classes; such as providing <a href="/confluence/display/CAMEL/Type+Converter"
title="Type Converter">Type Converter</a> support for Spring Resources etc</li>
	<li>Allows Spring to dependency inject <a href="/confluence/display/CAMEL/Component"
title="Component">Component</a> instances or the <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> instance itself and auto-expose Spring beans
as components and endpoints.</li>
	<li>Allows you to reuse the <a href="/confluence/display/CAMEL/Spring+Testing" title="Spring
Testing">Spring Testing</a> framework to simplify your unit and integration testing
using <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns" title="Enterprise
Integration Patterns">Enterprise Integration Patterns</a> and Camel's powerful <a
href="/confluence/display/CAMEL/Mock" title="Mock">Mock</a> and <a href="/confluence/display/CAMEL/Test"
title="Test">Test</a> endpoints</li>
</ul>


<h2><a name="Spring-UsingSpringtoconfiguretheCamelContext"></a>Using Spring
to configure the CamelContext</h2>

<p>You can configure a CamelContext inside any spring.xml using the <a href="http://camel.apache.org/maven/camel-spring/apidocs/org/apache/camel/spring/CamelContextFactoryBean.html"
class="external-link" rel="nofollow">CamelContextFactoryBean</a>. This will automatically
<a href="/confluence/display/CAMEL/Lifecycle" title="Lifecycle">start</a> the
<a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a>
along with any referenced <a href="/confluence/display/CAMEL/Routes" title="Routes">Routes</a>
along any referenced <a href="/confluence/display/CAMEL/Component" title="Component">Component</a>
and <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
instances.</p>

<ul>
	<li>Adding Camel schema</li>
	<li>Configure <a href="/confluence/display/CAMEL/Routes" title="Routes">Routes</a>
in two ways:
	<ul>
		<li>Using Java Code</li>
		<li>Using Spring XML</li>
	</ul>
	</li>
</ul>


<h3><a name="Spring-AddingCamelSchema"></a>Adding Camel Schema</h3>
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>For Camel 1.x you need to use
the following namespace:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
http:<span class="code-comment">//activemq.apache.org/camel/schema/spring</span>
</pre>
</div></div>
<p>with the following schema location:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
http:<span class="code-comment">//activemq.apache.org/camel/schema/spring/camel-spring.xsd</span>
</pre>
</div></div></td></tr></table></div>
<p>You need to add Camel to the <tt>schemaLocation</tt> declaration</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
http:<span class="code-comment">//camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd</span>
</pre>
</div></div>

<p>So the XML file looks like this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
</pre>
</div></div>

<h4><a name="Spring-Usingcamel%3Anamespace"></a>Using camel: namespace</h4>
<p>Or you can refer to camel XSD in the XML declaration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
xmlns:camel=<span class="code-quote">"http:<span class="code-comment">//activemq.apache.org/camel/schema/spring"</span></span>
</pre>
</div></div>
<p>... so the declaration is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;beans xmlns=<span class="code-quote">"http://www.springframework.org/schema/beans"</span>
       <span class="code-keyword">xmlns:xsi</span>=<span class="code-quote">"http://www.w3.org/2001/XMLSchema-instance"</span>
       <span class="code-keyword">xmlns:camel</span>=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
</pre>
</div></div>
<p>... and then use the camel: namespace prefix, and you can omit the inline namespace
declaration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camel:camelContext id=<span
class="code-quote">"camel5"</span>&gt;</span>
  <span class="code-tag">&lt;camel:package&gt;</span>org.apache.camel.spring.example<span
class="code-tag">&lt;/camel:package&gt;</span>
<span class="code-tag">&lt;/camel:camelContext&gt;</span>
</pre>
</div></div>

<h4><a name="Spring-AdvancedconfigurationusingSpring"></a>Advanced configuration
using Spring</h4>
<p>See more details at <a href="/confluence/display/CAMEL/Advanced+configuration+of+CamelContext+using+Spring"
title="Advanced configuration of CamelContext using Spring">Advanced configuration of CamelContext
using Spring</a></p>

<h3><a name="Spring-UsingJavaCode"></a>Using Java Code</h3>

<p>You can use Java Code to define your <a href="/confluence/display/CAMEL/RouteBuilder"
title="RouteBuilder">RouteBuilder</a> implementations. These can be defined as beans
in spring and then referenced in your camel context e.g.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">  <span class="code-tag">&lt;camelContext id=<span
class="code-quote">"camel5"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;routeBuilder ref=<span class="code-quote">"myBuilder"</span>
/&gt;</span>    
  <span class="code-tag">&lt;/camelContext&gt;</span>
  
  <span class="code-tag">&lt;bean id=<span class="code-quote">"myBuilder"</span>
class=<span class="code-quote">"org.apache.camel.spring.example.test1.MyRouteBuilder"</span>/&gt;</span>
  
<span class="code-tag">&lt;/beans&gt;</span>
</pre>
</div></div>

<h4><a name="Spring-Using%3Cpackage%3E"></a>Using &lt;package&gt;</h4>
<p>Camel also provides a powerful feature that allows for the automatic discovery and
initialization of routes in given packages. This is configured by adding tags to the camel
context in your spring context definition, specifying the packages to be recursively searched
for <a href="/confluence/display/CAMEL/RouteBuilder" title="RouteBuilder">RouteBuilder</a>
implementations. To use this feature in 1.X, requires a &lt;package&gt;&lt;/package&gt;
tag specifying a comma separated list of packages that should be searched e.g.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;camelContext http://activemq.apache.org/camel/schema/spring"&gt;</span>
    <span class="code-tag">&lt;package&gt;</span>org.apache.camel.spring.config.scan.route<span
class="code-tag">&lt;/package&gt;</span>
  <span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td>Use caution when specifying
the package name as <tt>org.apache.camel</tt> or a sub package of this. This causes
Camel to search in its own packages for your routes which could cause problems.</td></tr></table></div>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Will ignore
already instantiated classes</b><br />The &lt;package&gt; and &lt;packageScan&gt;
will skip any classes which has already been created by Spring etc. So if you define a route
builder as a spring bean tag then that class will be skipped. You can include those beans
using <tt>&lt;routeBuilder ref="theBeanId"/&gt;</tt> or the <tt>&lt;contextScan/&gt;</tt>
feature.</td></tr></table></div>

<h4><a name="Spring-Using%3CpackageScan%3E"></a>Using &lt;packageScan&gt;</h4>

<p>In Camel 2.0 this has been extended to allow selective inclusion and exclusion of
discovered route classes using Ant like path matching. In spring this is specified by adding
a &lt;packageScan/&gt; tag. The tag must contain one or more 'package' elements (similar
to 1.x), and optionally one or more 'includes' or 'excludes' elements specifying patterns
to be applied to the fully qualified names of the discovered classes. e.g.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;camelContext xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;packageScan&gt;</span>
      <span class="code-tag">&lt;package&gt;</span>org.example.routes<span
class="code-tag">&lt;/package&gt;</span>
      <span class="code-tag">&lt;excludes&gt;</span>**.*Excluded*<span
class="code-tag">&lt;/excludes&gt;</span>
      <span class="code-tag">&lt;includes&gt;</span>**.*<span class="code-tag">&lt;/includes&gt;</span>
    <span class="code-tag">&lt;/packageScan&gt;</span>
  <span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>Exclude patterns are applied before the include patterns. If no include or exclude
patterns are defined then all the Route classes discovered in the packages will be returned.</p>

<p>In the above example, camel will scan all the 'org.example.routes' package and any
subpackages for RouteBuilder classes. Say the scan finds two RouteBuilders, one in org.example.routes
called 'MyRoute" and another 'MyExcludedRoute' in a subpackage 'excluded'. The fully qualified
names of each of the classes are extracted (org.example.routes.MyRoute, org.example.routes.excluded.MyExcludedRoute)
and the include and exclude patterns are applied. </p>

<p>The exclude pattern &#42;&#42;.&#42;Excluded&#42; is going to match
the fqcn 'org.example.routes.excluded.MyExcludedRoute' and veto camel from initializing it.</p>

<p>Under the covers, this is using Spring's <a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html"
class="external-link" rel="nofollow">AntPatternMatcher</a> implementation, which
matches as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
? matches one character
* matches zero or more characters
** matches zero or more segments of a fully qualified name
</pre>
</div></div>

<p>For example:</p>

<p>&#42;&#42;.&#42;Excluded&#42; would match org.simple.Excluded, org.apache.camel.SomeExcludedRoute
or org.example.RouteWhichIsExcluded</p>

<p>&#42;&#42;.??cluded&#42; would match org.simple.IncludedRoute, org.simple.Excluded
but not match org.simple.PrecludedRoute</p>

<h4><a name="Spring-UsingcontextScan"></a>Using contextScan</h4>
<p><b>Available as of Camel 2.4</b></p>

<p>You can allow Camel to scan the container context, e.g. the Spring <tt>ApplicationContext</tt>
for route builder instances. This allow you to use the Spring <tt>&lt;component-scan&gt;</tt>
feature and have Camel pickup any RouteBuilder instances which was created by Spring in its
scan process.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!--
enable Spring @Component scan --&gt;</span></span>
<span class="code-tag">&lt;context:component-scan base-package=<span class="code-quote">"org.apache.camel.spring.issues.contextscan"</span>/&gt;</span>

<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span>
xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- and then let
Camel use those @Component scanned route builders --&gt;</span></span>
    <span class="code-tag">&lt;contextScan/&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>This allows you to just annotate your routes using the Spring <tt>@Component</tt>
and have those routes included by Camel</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@Component
<span class="code-keyword">public</span> class MyRoute <span class="code-keyword">extends</span>
SpringRouteBuilder {

    @Override
    <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span>
Exception {
        from(<span class="code-quote">"direct:start"</span>).to(<span class="code-quote">"mock:result"</span>);
    }
}
</pre>
</div></div>

<p>You can also use the ANT style for inclusion and exclusion, as mentioned above in
the <tt>&lt;packageScan&gt;</tt> documentation.</p>


<h4><a name="Spring-Testtimeexclusion."></a>Test time exclusion. </h4>

<p>At test time it is often desirable to be able to selectively exclude matching routes
from being initalized that are not applicable or useful to the test scenario. For instance
you might a spring context file routes-context.xml and three Route builders RouteA, RouteB
and RouteC in the 'org.example.routes' package. The packageScan definition would discover
all three of these routes and initialize them.</p>

<p>Say RouteC is not applicable to our test scenario and generates a lot of noise during
test. It would be nice to be able to exclude this route from this specific test. The SpringTestSupport
class has been modified to allow this. It provides two methods (excludedRoute and excludedRoutes)
that may be overridden to exclude a single class or an array of classes.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class RouteAandRouteBOnlyTest <span
class="code-keyword">extends</span> SpringTestSupport {
    @Override      
    <span class="code-keyword">protected</span> <span class="code-object">Class</span>
excludeRoute() {
        <span class="code-keyword">return</span> RouteC.class;
    }
}
</pre>
</div></div>
<p>In order to hook into the camelContext initialization by spring to exclude the MyExcludedRouteBuilder.class
we need to intercept the spring context creation. When overriding createApplicationContext
to create the spring context, we call the getRouteExcludingApplicationContext() method to
provide a special parent spring context that takes care of the exclusion.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@Override
<span class="code-keyword">protected</span> AbstractXmlApplicationContext createApplicationContext()
{
    <span class="code-keyword">return</span> <span class="code-keyword">new</span>
ClassPathXmlApplicationContext(<span class="code-keyword">new</span> <span
class="code-object">String</span>[] {<span class="code-quote">"routes-context.xml"</span>},
getRouteExcludingApplicationContext());
}
</pre>
</div></div>
<p>RouteC will now be excluded from initialization. Similarly, in another test that
is testing only RouteC, we could exclude RouteB and RouteA by overriding </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
@Override
<span class="code-keyword">protected</span> <span class="code-object">Class</span>[]
excludeRoutes() {
    <span class="code-keyword">return</span> <span class="code-keyword">new</span>
<span class="code-object">Class</span>[]{RouteA.class, RouteB.class};
}
</pre>
</div></div>
<h3><a name="Spring-UsingSpringXML"></a>Using Spring XML</h3>

<p>You can use Spring 2.0 XML configuration to specify your <a href="/confluence/display/CAMEL/Xml+Configuration"
title="Xml Configuration">Xml Configuration</a> for <a href="/confluence/display/CAMEL/Routes"
title="Routes">Routes</a> such as in the following <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactory.xml"
class="external-link" rel="nofollow">example</a>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span
class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"seda:start"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h2><a name="Spring-ConfiguringComponentsandEndpoints"></a>Configuring Components
and Endpoints</h2>

<p>You can configure your <a href="/confluence/display/CAMEL/Component" title="Component">Component</a>
or <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
instances in your <a href="/confluence/display/CAMEL/Spring" title="Spring">Spring</a>
XML as follows in <a href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml"
class="external-link" rel="nofollow">this example</a>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext id=<span
class="code-quote">"camel"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"activemq"</span>
class=<span class="code-quote">"org.apache.camel.component.jms.JmsComponent"</span>&gt;</span>
  <span class="code-tag">&lt;property name=<span class="code-quote">"connectionFactory"</span>&gt;</span>
    <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.activemq.ActiveMQConnectionFactory"</span>&gt;</span>
      <span class="code-tag">&lt;property name=<span class="code-quote">"brokerURL"</span>
value=<span class="code-quote">"vm://localhost?broker.persistent=false"</span>/&gt;</span>
    <span class="code-tag">&lt;/bean&gt;</span>
  <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>
<p>Which allows you to configure a component using some name (activemq in the above
example), then you can refer to the component using <b>activemq:[queue:&#124;topic:]destinationName</b>.
This works by the SpringCamelContext lazily fetching components from the spring context for
the scheme name you use for <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
<a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a>.</p>

<p>For more detail see <a href="/confluence/display/CAMEL/How+do+I+configure+endpoints"
title="How do I configure endpoints">Configuring Endpoints and Components</a>.</p>

<h3><a name="Spring-CamelContextAware"></a>CamelContextAware</h3>

<p>If you want to be injected with the <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> in your POJO just implement the <a href="http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/CamelContextAware.html"
class="external-link" rel="nofollow">CamelContextAware interface</a>; then when Spring
creates your POJO the CamelContext will be injected into your POJO. Also see the <a href="/confluence/display/CAMEL/Bean+Integration"
title="Bean Integration">Bean Integration</a> for further injections.</p>

<h3><a name="Spring-Seealso"></a>See also</h3>

<ul>
	<li><a href="/confluence/display/CAMEL/Tutorial-JmsRemoting" title="Tutorial-JmsRemoting">Spring
JMS Tutorial</a></li>
	<li><a href="/confluence/display/CAMEL/Creating+a+new+Spring+based+Camel+Route"
title="Creating a new Spring based Camel Route">Creating a new Spring based Camel Route</a></li>
	<li><a href="/confluence/display/CAMEL/Spring+Example" title="Spring Example">Spring
example</a></li>
	<li><a href="/confluence/display/CAMEL/Xml+Reference" title="Xml Reference">Xml
Reference</a></li>
	<li><a href="/confluence/display/CAMEL/Advanced+configuration+of+CamelContext+using+Spring"
title="Advanced configuration of CamelContext using Spring">Advanced configuration of CamelContext
using Spring</a></li>
</ul>


    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Spring">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=52911&revisedVersion=34&originalVersion=33">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Spring?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message