Author: buildbot
Date: Sun May 13 08:18:56 2018
New Revision: 1029822

Log:
Production update by buildbot for camel

Modified:
    websites/production/camel/content/cache/main.pageCache
    websites/production/camel/content/spring.html

Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/camel/content/spring.html
==============================================================================
--- websites/production/camel/content/spring.html (original)
+++ websites/production/camel/content/spring.html Sun May 13 08:18:56 2018
@@ -36,6 +36,16 @@
     <![endif]-->
 
 
+  <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css' 
rel='stylesheet' type='text/css' />
+  <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css' 
rel='stylesheet' type='text/css' />
+  <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js' 
type='text/javascript'></script>
+  <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js' 
type='text/javascript'></script>
+  <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js' 
type='text/javascript'></script>
+  
+  <script type="text/javascript">
+  SyntaxHighlighter.defaults['toolbar'] = false;
+  SyntaxHighlighter.all();
+  </script>
 
     <title>
     Apache Camel: Spring
@@ -78,68 +88,122 @@
        <tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="Spring-SpringSupport">Spring 
Support</h2><p>Apache Camel is designed to work nicely with the <a shape="rect" 
class="external-link" href="http://www.springframework.org/"; 
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 
shape="rect" href="jms.html">JMS</a> and <a shape="rect" 
href="jpa.html">JPA</a></li><li>Camel works with Spring 2 XML processing with 
the <a shape="rect" href="xml-configuration.html">Xml 
Configuration</a></li><li>Camel Spring XML Schema's is defined at <a 
shape="rect" href="xml-reference.html">Xml Reference</a></li><li>Camel supports 
a powerful version of <a shape="rect" href="spring-remoting.html">Spring 
Remoting</a> which can use powerful routing between the client and server side 
along with using all of the available <a shape="rect" 
href="components.html">Components</a> for the transport</li><li>Camel provides p
 owerful <a shape="rect" href="bean-integration.html">Bean Integration</a> with 
any bean defined in a Spring 
<strong><code>ApplicationContext</code></strong>.</li><li>Camel integrates with 
various Spring helper classes; such as providing <a shape="rect" 
href="type-converter.html">Type Converter</a> support for Spring Resources 
etc</li><li>Allows Spring to dependency inject <a shape="rect" 
href="component.html">Component</a> instances or the <a shape="rect" 
href="camelcontext.html">CamelContext</a> instance itself and auto-expose 
Spring beans as components and endpoints.</li><li>Allows you to reuse the <a 
shape="rect" href="spring-testing.html">Spring Testing</a> framework to 
simplify your unit and integration testing using <a shape="rect" 
href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a> 
and Camel's powerful <a shape="rect" href="mock.html">Mock</a> and <a 
shape="rect" href="test.html">Test</a> 
endpoints</li><li>From&#160;<strong>Camel 2.15</strong>: Cam
 el supports Spring Boot using the&#160;<code><a shape="rect" 
href="spring-boot.html">camel-spring-boot</a></code> 
component.</li><li>From&#160;<strong>Camel 2.17.1</strong>: Camel supports 
Spring Cache based Idempotent repository</li></ul><h2 
id="Spring-UsingSpringtoconfiguretheCamelContext">Using Spring to configure the 
CamelContext</h2><p>You can configure 
a&#160;<strong><code>CamelContext</code></strong> inside 
any&#160;<strong><code>spring.xml</code></strong> using the <a shape="rect" 
class="external-link" 
href="http://camel.apache.org/maven/current/camel-spring/apidocs/org/apache/camel/spring/CamelContextFactoryBean.html";>CamelContextFactoryBean</a>.
 This will automatically <a shape="rect" href="lifecycle.html">start</a> the <a 
shape="rect" href="camelcontext.html">CamelContext</a> along with any 
referenced <a shape="rect" href="routes.html">Routes</a> along any referenced 
<a shape="rect" href="component.html">Component</a> and <a shape="rect" 
href="endpoint.html">Endpoint</a> 
 instances.</p><ul><li>Adding Camel schema</li><li>Configure <a shape="rect" 
href="routes.html">Routes</a> in two ways:<ul><li>Using Java Code</li><li>Using 
Spring XML</li></ul></li></ul><h3 id="Spring-AddingCamelSchema">Adding Camel 
Schema</h3><rich-text-body><p>For Camel 1.x you need to use the following 
namespace:</p><plain-text-body>http://activemq.apache.org/camel/schema/spring
-</plain-text-body><p>with the following schema 
location:</p><plain-text-body>http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
-</plain-text-body></rich-text-body><p>You need to add Camel to the 
<strong><code>schemaLocation</code></strong> 
declaration</p><plain-text-body>http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
-</plain-text-body><p>So the XML file looks like this:</p><parameter 
ac:name="">xml</parameter><plain-text-body>&lt;beans 
xmlns="http://www.springframework.org/schema/beans";
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-       xsi:schemaLocation="
+<div class="wiki-content maincontent"><h2 id="Spring-SpringSupport">Spring 
Support</h2><p>Apache Camel is designed to work nicely with the <a shape="rect" 
class="external-link" href="http://www.springframework.org/"; 
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 
shape="rect" href="jms.html">JMS</a> and <a shape="rect" 
href="jpa.html">JPA</a></li><li>Camel works with Spring 2 XML processing with 
the <a shape="rect" href="xml-configuration.html">Xml 
Configuration</a></li><li>Camel Spring XML Schema's is defined at <a 
shape="rect" href="xml-reference.html">Xml Reference</a></li><li>Camel supports 
a powerful version of <a shape="rect" href="spring-remoting.html">Spring 
Remoting</a> which can use powerful routing between the client and server side 
along with using all of the available <a shape="rect" 
href="components.html">Components</a> for the transport</li><li>Camel provides p
 owerful <a shape="rect" href="bean-integration.html">Bean Integration</a> with 
any bean defined in a Spring 
<strong><code>ApplicationContext</code></strong>.</li><li>Camel integrates with 
various Spring helper classes; such as providing <a shape="rect" 
href="type-converter.html">Type Converter</a> support for Spring Resources 
etc</li><li>Allows Spring to dependency inject <a shape="rect" 
href="component.html">Component</a> instances or the <a shape="rect" 
href="camelcontext.html">CamelContext</a> instance itself and auto-expose 
Spring beans as components and endpoints.</li><li>Allows you to reuse the <a 
shape="rect" href="spring-testing.html">Spring Testing</a> framework to 
simplify your unit and integration testing using <a shape="rect" 
href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a> 
and Camel's powerful <a shape="rect" href="mock.html">Mock</a> and <a 
shape="rect" href="test.html">Test</a> 
endpoints</li><li>From&#160;<strong>Camel 2.15</strong>: Cam
 el supports Spring Boot using the&#160;<code><a shape="rect" 
href="spring-boot.html">camel-spring-boot</a></code> 
component.</li><li>From&#160;<strong>Camel 2.17.1</strong>: Camel supports 
Spring Cache based Idempotent repository</li></ul><h2 
id="Spring-UsingSpringtoconfiguretheCamelContext">Using Spring to configure the 
CamelContext</h2><p>You can configure 
a&#160;<strong><code>CamelContext</code></strong> inside 
any&#160;<strong><code>spring.xml</code></strong> using the <a shape="rect" 
class="external-link" 
href="http://camel.apache.org/maven/current/camel-spring/apidocs/org/apache/camel/spring/CamelContextFactoryBean.html";>CamelContextFactoryBean</a>.
 This will automatically <a shape="rect" href="lifecycle.html">start</a> the <a 
shape="rect" href="camelcontext.html">CamelContext</a> along with any 
referenced <a shape="rect" href="routes.html">Routes</a> along any referenced 
<a shape="rect" href="component.html">Component</a> and <a shape="rect" 
href="endpoint.html">Endpoint</a> 
 instances.</p><ul><li>Adding Camel schema</li><li>Configure <a shape="rect" 
href="routes.html">Routes</a> in two ways:<ul><li>Using Java Code</li><li>Using 
Spring XML</li></ul></li></ul><h3 id="Spring-AddingCamelSchema">Adding Camel 
Schema</h3><p>For Camel 1.x you need to use the following namespace:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[http://activemq.apache.org/camel/schema/spring]]></script>
+</div></div><p><br clear="none">with the following schema location:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[http://activemq.apache.org/camel/schema/spring/camel-spring.xsd]]></script>
+</div></div><p>You need to add Camel to the 
<strong><code>schemaLocation</code></strong> declaration</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd]]></script>
+</div></div><p>So the XML file looks like this:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;beans 
xmlns=&quot;http://www.springframework.org/schema/beans&quot;
+       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
+       xsi:schemaLocation=&quot;
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    &quot;&gt;]]></script>
+</div></div><p>&#160;</p><h4 
id="Spring-Usingcamel:Namespace">Using&#160;<code>camel:</code> 
Namespace</h4><p>Or you can refer to the camel XSD in the XML 
declaration:</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[xmlns:camel=&quot;http://camel.apache.org/schema/spring&quot;]]></script>
+</div></div><p><br clear="none">... so the declaration is:</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;beans 
xmlns=&quot;http://www.springframework.org/schema/beans&quot;
+       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
+       xmlns:camel=&quot;http://camel.apache.org/schema/spring&quot;
+       xsi:schemaLocation=&quot;
           http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
-          http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd"&gt;
-</plain-text-body><h4 
id="Spring-Usingcamel:Namespace">Using&#160;<code>camel:</code> 
Namespace</h4><p>Or you can refer to the camel XSD in the XML 
declaration:</p><plain-text-body>xmlns:camel="http://camel.apache.org/schema/spring";
-</plain-text-body><p>... so the declaration 
is:<plain-text-body>{snippet:id=xsdlocation|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}</plain-text-body>...
 and then use the&#160;<strong><code>camel:</code></strong> namespace prefix, 
and you can omit the inline namespace 
declaration:<plain-text-body>{snippet:id=example5|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextFactoryBean.xml}</plain-text-body></p><h4
 id="Spring-AdvancedConfigurationUsingSpring">Advanced Configuration Using 
Spring</h4><p>See more details at <a shape="rect" 
href="advanced-configuration-of-camelcontext-using-spring.html">Advanced 
configuration of CamelContext using Spring</a></p><h3 
id="Spring-UsingJavaCode">Using Java Code</h3><p>You can use Java Code to 
define your <a shape="rect" href="routebuilder.html">RouteBuilder</a> 
implementations. These can be defined as beans in spring and 
 then referenced in your camel context 
e.g.<plain-text-body>{snippet:id=example5|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/camelContextRouteBuilderRef.xml}</plain-text-body></p><h4
 
id="Spring-Using&lt;package&gt;">Using&#160;<code>&lt;package&gt;</code></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 shape="rect" 
href="routebuilder.html">RouteBuilder</a> implementations. To use this feature 
in <strong><code>1.X</code></strong>, requires 
a&#160;<strong><code>&lt;package&gt;&lt;/package&gt;</code></strong> tag 
specifying a comma separated list of packages that should be searched 
e.g.</p><parameter ac:name="">xml</parameter><plain-text-body>  
&lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
-    &lt;package&gt;org.apache.camel.spring.config.scan.route&lt;/package&gt;
-  &lt;/camelContext&gt;
-</plain-text-body><rich-text-body><p>Use caution when specifying the package 
name as <strong><code>org.apache.camel</code></strong> or a sub package of 
this. This causes Camel to search in its own packages for your routes which 
could cause problems.</p></rich-text-body><parameter ac:name="title">Will 
ignore already instantiated 
classes</parameter><rich-text-body><p>The&#160;<strong><code>&lt;package&gt;</code></strong>
 and&#160;<strong><code>&lt;packageScan&gt;</code></strong> 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 <strong><code>&lt;routeBuilder 
ref="theBeanId"/&gt;</code></strong> or the 
<strong><code>&lt;contextScan&gt;</code></strong> 
feature.</p></rich-text-body><h4 
id="Spring-Using&lt;packageScan&gt;">Using&#160;<code>&lt;packageScan&gt;</code></h4><p>In
 Camel 2.0 this has been extended to allow selective inclusion and exclusion o
 f discovered route classes using Ant like path matching. In spring this is 
specified by adding a&#160;<strong><code>&lt;packageScan/&gt;</code></strong> 
tag. The tag must contain one or 
more&#160;<strong><code>package</code></strong> elements (similar to 
<strong><code>1.x</code></strong>), and optionally one or 
more&#160;<strong><code>includes</code></strong> 
or&#160;<strong><code>excludes</code></strong> elements specifying patterns to 
be applied to the fully qualified names of the discovered classes. 
e.g.,</p><parameter ac:name="">xml</parameter><plain-text-body>  
&lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
-    &lt;packageScan&gt;
-      &lt;package&gt;org.example.routes&lt;/package&gt;
-      &lt;excludes&gt;**.*Excluded*&lt;/excludes&gt;
-      &lt;includes&gt;**.*&lt;/includes&gt;
-    &lt;/packageScan&gt;
-  &lt;/camelContext&gt;
-</plain-text-body><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&#160;<strong><code>org.example.routes</code></strong> package 
and any subpackages for&#160;<strong><code>RouteBuilder</code></strong> 
classes. Say the scan finds two <strong><code>RouteBuilders</code></strong>, 
one in&#160;<strong><code>org.example.routes</code></strong> 
called&#160;<strong><code>MyRoute</code></strong> and 
another&#160;<strong><code>MyExcludedRoute</code></strong> in a subpackage 
<strong><code>excluded</code></strong>. The fully qualified names of each of 
the classes are extracted 
(<strong><code>org.example.routes.MyRoute</code></strong>,&#160;<strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong>
 ) and the include and exclude patterns are applied.</p><p>The exclude 
pattern&#160;<strong><code>**.*Exclu
 ded*</code></strong> is going to match the FQCN 
<strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong> and 
veto camel from initializing it.</p><p>Under the covers, this is using Spring's 
<a shape="rect" class="external-link" 
href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html";
 rel="nofollow">AntPatternMatcher</a> implementation, which matches as 
follows</p><plain-text-body>? matches one character
-* matches zero or more characters
-** matches zero or more segments of a fully qualified name
-</plain-text-body><p>For 
example:</p><p><strong><code>**.*Excluded*</code></strong> would match 
<strong><code>org.simple.Excluded</code></strong>,&#160;<strong><code>org.apache.camel.SomeExcludedRoute</code></strong>
 or 
<strong><code>org.example.RouteWhichIsExcluded</code></strong>.</p><p><strong><code>**.??cluded*</code></strong>
 would match 
<strong><code>org.simple.IncludedRoute</code></strong>,&#160;<strong><code>org.simple.Excluded</code></strong>
 but <em>not</em> match 
<strong><code>org.simple.PrecludedRoute</code></strong>.</p><h4 
id="Spring-UsingcontextScan">Using&#160;<code>contextScan</code></h4><p><strong>Available
 as of Camel 2.4</strong></p><p>You can allow Camel to scan the container 
context, e.g. the Spring <strong><code>ApplicationContext</code></strong> for 
route builder instances. This allow you to use the Spring 
<strong><code>&lt;component-scan&gt;</code></strong> feature and have Camel 
pickup any&#160;<strong><code>RouteBuilder</code></strong> instances which was 
 created by Spring in its scan 
process.<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/contextscan/SpringRouteIsComponentAnnotatedTest.xml}</plain-text-body>This
 allows you to just annotate your routes using the Spring 
<strong><code>@Component</code></strong> and have those routes included by 
Camel:</p><plain-text-body>@Component
-public class MyRoute extends SpringRouteBuilder {
+          http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd&quot;&gt;
 
-    @Override
-    public void configure() throws Exception {
-        from("direct:start")
-          .to("mock:result");
-    }
-}
-</plain-text-body><p>You can also use the ANT style for inclusion and 
exclusion, as mentioned above in the 
<strong><code>&lt;packageScan&gt;</code></strong> 
documentation.</p><p><parameter ac:name=""><a shape="rect" class="unresolved" 
href="#">how do i import routes from other xml files</a></parameter></p><h4 
id="Spring-TestTimeExclusion.">Test Time Exclusion.</h4><p>At test time it is 
often desirable to be able to selectively exclude matching routes from being 
initialized that are not applicable or useful to the test scenario. For 
instance you might a spring context 
file&#160;<strong><code>routes-context.xml</code></strong> and three Route 
builders <strong><code>RouteA</code>,&#160;</strong><code>RouteB</code> 
and&#160;<strong><code>RouteC</code></strong> in 
the&#160;<strong><code>org.example.routes</code></strong> package. 
The&#160;<strong><code>packageScan</code></strong> definition would discover 
all three of these routes and initialize 
them.</p><p>Say&#160;<strong><code>RouteC<
 /code></strong> 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&#160;<strong><code>SpringTestSupport</code></strong> class 
has been modified to allow this. It provides two methods 
(<strong><code>excludedRoute</code></strong> and 
<strong><code>excludedRoutes</code></strong>) that may be overridden to exclude 
a single class or an array of classes.</p><parameter 
ac:name="">java</parameter><plain-text-body>public class 
RouteAandRouteBOnlyTest extends SpringTestSupport {
-    @Override      
-    protected Class excludeRoute() {
-        return RouteC.class;
-    }
-}
-</plain-text-body><p>In order to hook into 
the&#160;<strong><code>camelContext</code></strong> initialization by spring to 
exclude the&#160;<strong><code>MyExcludedRouteBuilder.class</code></strong> we 
need to intercept the spring context creation. When 
overriding&#160;<strong><code>createApplicationContext</code></strong> to 
create the spring context, we call 
the&#160;<strong><code>getRouteExcludingApplicationContext()</code></strong> 
method to provide a special parent spring context that takes care of the 
exclusion.</p><parameter ac:name="">java</parameter><plain-text-body>@Override
-protected AbstractXmlApplicationContext createApplicationContext() {
-    return new ClassPathXmlApplicationContext(new String[] 
{"routes-context.xml"}, getRouteExcludingApplicationContext());
-}
-</plain-text-body><p><strong><code>RouteC</code></strong> will now be excluded 
from initialization. Similarly, in another test that is testing only 
<strong><code>RouteC</code></strong>, we could 
exclude&#160;<strong><code>RouteB</code></strong> 
and&#160;<strong><code>RouteA</code></strong> by 
overriding:</p><plain-text-body>@Override
+]]></script>
+</div></div><p>... and then use the&#160;<strong><code>camel:</code></strong> 
namespace prefix, and you can omit the inline namespace declaration:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;camel:camelContext 
id=&quot;camel5&quot;&gt;
+  &lt;camel:package&gt;org.apache.camel.spring.example&lt;/camel:package&gt;
+&lt;/camel:camelContext&gt;
+]]></script>
+</div></div><h4 id="Spring-AdvancedConfigurationUsingSpring"><br 
clear="none">Advanced Configuration Using Spring</h4><p>See more details at <a 
shape="rect" 
href="advanced-configuration-of-camelcontext-using-spring.html">Advanced 
configuration of CamelContext using Spring</a></p><h3 
id="Spring-UsingJavaCode">Using Java Code</h3><p>You can use Java Code to 
define your <a shape="rect" href="routebuilder.html">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 pdl" style="border-width: 
1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;camelContext id=&quot;camel5&quot; 
xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
+  &lt;routeBuilder ref=&quot;myBuilder&quot; /&gt;    
+&lt;/camelContext&gt;
+
+&lt;bean id=&quot;myBuilder&quot; 
class=&quot;org.apache.camel.spring.example.test1.MyRouteBuilder&quot;/&gt;]]></script>
+</div></div><h4 
id="Spring-Using&lt;package&gt;">Using&#160;<code>&lt;package&gt;</code></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 shape="rect" 
href="routebuilder.html">RouteBuilder</a> implementations. To use this feature 
in <strong><code>1.X</code></strong>, requires 
a&#160;<strong><code>&lt;package&gt;&lt;/package&gt;</code></strong> tag 
specifying a comma separated list of packages that should be searched 
e.g.</p><p>camelContextRouteBuilderRef.xml</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;camel:camelContext 
id=&quot;camel5&quot;&gt;
+  &lt;camel:package&gt;org.apache.camel.spring.example&lt;/camel:package&gt;
+&lt;/camel:camelContext&gt;]]></script>
+</div></div><p>Use caution when specifying the package name as 
<strong><code>org.apache.camel</code></strong> or a sub package of this. This 
causes Camel to search in its own packages for your routes which could cause 
problems.</p><p>Will ignore already instantiated 
classes</p><p>The&#160;<strong><code>&lt;package&gt;</code></strong> 
and&#160;<strong><code>&lt;packageScan&gt;</code></strong> 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 <strong><code>&lt;routeBuilder 
ref="theBeanId"/&gt;</code></strong> or the 
<strong><code>&lt;contextScan&gt;</code></strong> feature.</p><h4 
id="Spring-Using&lt;packageScan&gt;">Using&#160;<code>&lt;packageScan&gt;</code></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&#160;<s
 trong><code>&lt;packageScan/&gt;</code></strong> tag. The tag must contain one 
or more&#160;<strong><code>package</code></strong> elements (similar to 
<strong><code>1.x</code></strong>), and optionally one or 
more&#160;<strong><code>includes</code></strong> 
or&#160;<strong><code>excludes</code></strong> elements specifying patterns to 
be applied to the fully qualified names of the discovered classes. 
e.g.,</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;camelContext 
xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt; 
+  &lt;packageScan&gt; 
+    &lt;package&gt;org.example.routes&lt;/package&gt; 
+    &lt;excludes&gt;**.*Excluded*&lt;/excludes&gt;
+    &lt;includes&gt;**.*&lt;/includes&gt;
+  &lt;/packageScan&gt;
+&lt;/camelContext&gt;]]></script>
+</div></div><p><br clear="none">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&#160;<strong><code>org.example.routes</code></strong> package and any 
subpackages for&#160;<strong><code>RouteBuilder</code></strong> classes. Say 
the scan finds two <strong><code>RouteBuilders</code></strong>, one 
in&#160;<strong><code>org.example.routes</code></strong> 
called&#160;<strong><code>MyRoute</code></strong> and 
another&#160;<strong><code>MyExcludedRoute</code></strong> in a subpackage 
<strong><code>excluded</code></strong>. The fully qualified names of each of 
the classes are extracted 
(<strong><code>org.example.routes.MyRoute</code></strong>,&#160;<strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong>
 ) and the include and exclude patterns are applied.</p><p>The exclude 
pattern&#160;<strong><cod
 e>**.*Excluded*</code></strong> is going to match the FQCN 
<strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong> and 
veto camel from initializing it.</p><p>Under the covers, this is using Spring's 
<a shape="rect" class="external-link" 
href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/util/AntPathMatcher.html";
 rel="nofollow">AntPatternMatcher</a> implementation, which matches as 
follows</p><p>? matches one character * matches zero or more characters ** 
matches zero or more segments of a fully qualified name</p><p>For 
example:</p><p><strong><code>**.*Excluded*</code></strong> would match 
<strong><code>org.simple.Excluded</code></strong>,&#160;<strong><code>org.apache.camel.SomeExcludedRoute</code></strong>
 or 
<strong><code>org.example.RouteWhichIsExcluded</code></strong>.</p><p><strong><code>**.??cluded*</code></strong>
 would match 
<strong><code>org.simple.IncludedRoute</code></strong>,&#160;<strong><code>org.simple.Excluded</code></
 strong> but <em>not</em> match 
<strong><code>org.simple.PrecludedRoute</code></strong>.</p><h4 
id="Spring-UsingcontextScan">Using&#160;<code>contextScan</code></h4><p><strong>Available
 as of Camel 2.4</strong></p><p>You can allow Camel to scan the container 
context, e.g. the Spring <strong><code>ApplicationContext</code></strong> for 
route builder instances. This allow you to use the Spring 
<strong><code>&lt;component-scan&gt;</code></strong> feature and have Camel 
pickup any&#160;<strong><code>RouteBuilder</code></strong> instances which was 
created by Spring in its scan process.</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;!-- enable Spring @Component scan --&gt;
+&lt;context:component-scan 
base-package=&quot;org.apache.camel.spring.issues.contextscan&quot;/&gt;
+
+&lt;camelContext xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
+    &lt;!-- and then let Camel use those @Component scanned route builders 
--&gt;
+    &lt;contextScan/&gt;
+&lt;/camelContext&gt;]]></script>
+</div></div><p>This allows you to just annotate your routes using the Spring 
<strong><code>@Component</code></strong> and have those routes included by 
Camel:</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[@Component 
+public class MyRoute extends SpringRouteBuilder {
+ @Override public void configure() throws Exception {
+    from(&quot;direct:start&quot;) .to(&quot;mock:result&quot;);
+ }
+}]]></script>
+</div></div><p>&#160;</p><p>You can also use the ANT style for inclusion and 
exclusion, as mentioned above in the 
<strong><code>&lt;packageScan&gt;</code></strong> documentation.</p><p><a 
shape="rect" class="unresolved" href="#">how do i import routes from other xml 
files</a></p><h4 id="Spring-TestTimeExclusion.">Test Time Exclusion.</h4><p>At 
test time it is often desirable to be able to selectively exclude matching 
routes from being initialized that are not applicable or useful to the test 
scenario. For instance you might a spring context 
file&#160;<strong><code>routes-context.xml</code></strong> and three Route 
builders <strong><code>RouteA</code>,&#160;</strong><code>RouteB</code> 
and&#160;<strong><code>RouteC</code></strong> in 
the&#160;<strong><code>org.example.routes</code></strong> package. 
The&#160;<strong><code>packageScan</code></strong> definition would discover 
all three of these routes and initialize 
them.</p><p>Say&#160;<strong><code>RouteC</code></strong> is not appl
 icable 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&#160;<strong><code>SpringTestSupport</code></strong> class has been 
modified to allow this. It provides two methods 
(<strong><code>excludedRoute</code></strong> and 
<strong><code>excludedRoutes</code></strong>) that may be overridden to exclude 
a single class or an array of classes.</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[public class RouteAandRouteBOnlyTest extends 
SpringTestSupport {
+  @Override 
+  protected Class excludeRoute() {
+    return RouteC.class; 
+  }
+}]]></script>
+</div></div><p>java</p><p>In order to hook into 
the&#160;<strong><code>camelContext</code></strong> initialization by spring to 
exclude the&#160;<strong><code>MyExcludedRouteBuilder.class</code></strong> we 
need to intercept the spring context creation. When 
overriding&#160;<strong><code>createApplicationContext</code></strong> to 
create the spring context, we call 
the&#160;<strong><code>getRouteExcludingApplicationContext()</code></strong> 
method to provide a special parent spring context that takes care of the 
exclusion.</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[@Override 
+protected AbstractXmlApplicationContext createApplicationContext() { 
+  return new ClassPathXmlApplicationContext(
+       new String[] {&quot;routes-context.xml&quot;}, 
getRouteExcludingApplicationContext()); 
+}]]></script>
+</div></div><p><strong><code><br clear="none">RouteC</code></strong> will now 
be excluded from initialization. Similarly, in another test that is testing 
only <strong><code>RouteC</code></strong>, we could 
exclude&#160;<strong><code>RouteB</code></strong> 
and&#160;<strong><code>RouteA</code></strong> by overriding:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[@Override 
 protected Class[] excludeRoutes() {
-    return new Class[]{RouteA.class, RouteB.class};
-}
-</plain-text-body><h3 id="Spring-UsingSpringXML">Using Spring XML</h3><p>You 
can use Spring 2.0 XML configuration to specify your <a shape="rect" 
href="xml-configuration.html">Xml Configuration</a> for <a shape="rect" 
href="routes.html">Routes</a> such as in the following <a shape="rect" 
class="external-link" 
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactory.xml";>example</a>.<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactory.xml}</plain-text-body></p><h2
 id="Spring-ConfiguringComponentsandEndpoints">Configuring Components and 
Endpoints</h2><p>You can configure your <a shape="rect" 
href="component.html">Component</a> or <a shape="rect" 
href="endpoint.html">Endpoint</a> instances in your <a shape="rect" 
href="spring.html">Spring</a> XML as follows in <a shape="rect" class="extern
 al-link" 
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml";>this
 
example</a>.<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml}</plain-text-body>Which
 allows you to configure a component using some name 
(<strong><code>activemq</code></strong> in the above example), then you can 
refer to the component using 
<strong><code>activemq:[queue:|topic:]destinationName</code></strong>. This 
works by the&#160;<strong><code>SpringCamelContext</code></strong> lazily 
fetching components from the spring context for the scheme name you use for <a 
shape="rect" href="endpoint.html">Endpoint</a> <a shape="rect" 
href="uris.html">URIs</a>.</p><p>For more detail see <a shape="rect" 
href="how-do-i-configure-endpoints.html">Configuring Endpoints and 
Components</a>.</p><h2 id="Spring-SpringCacheIdempotentRepo
 sitory">Spring Cache Idempotent Repository</h2><p>Available as of 
<strong>Camel 2.17.1</strong></p><parameter 
ac:name="language">xml</parameter><plain-text-body>&lt;bean id="repo" 
class="org.apache.camel.spring.processor.idempotent.SpringCacheIdempotentRepository"&gt;
-    &lt;constructor-arg&gt;
-       &lt;bean class="org.springframework.cache.guava.GuavaCacheManager"/&gt;
-    &lt;/constructor-arg&gt;
-    &lt;constructor-arg value="idempotent"/&gt;
-&lt;/bean&gt;
-
-&lt;camelContext xmlns="http://camel.apache.org/schema/spring"&gt;
-    &lt;route id="idempotent-cache"&gt;
-        &lt;from uri="direct:start" /&gt;
-        &lt;idempotentConsumer messageIdRepositoryRef="repo" 
skipDuplicate="true"&gt;
-            &lt;header&gt;MessageId&lt;/header&gt;
-            &lt;to 
uri="log:org.apache.camel.spring.processor.idempotent?level=INFO&amp;amp;showAll=true&amp;amp;multiline=true"
 /&gt;
-            &lt;to uri="mock:result"/&gt;
-        &lt;/idempotentConsumer&gt;
-    &lt;/route&gt;
-&lt;/camelContext&gt;</plain-text-body><p>&#160;</p><p>&#160;</p><h3 
id="Spring-CamelContextAware">CamelContextAware</h3><p>If you want to be 
injected with the <a shape="rect" href="camelcontext.html">CamelContext</a> in 
your POJO just implement the <a shape="rect" class="external-link" 
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContextAware.html";>CamelContextAware
 interface</a>; then when Spring creates your POJO 
the&#160;<strong><code>CamelContext</code></strong> will be injected into your 
POJO. Also see the <a shape="rect" href="bean-integration.html">Bean 
Integration</a> for further injections.</p><h2 
id="Spring-IntegrationTesting">Integration Testing</h2><p>To avoid a hung route 
when testing using Spring Transactions see the note about Spring Integration 
Testing under&#160;<a shape="rect" 
href="transactional-client.html">Transactional Client</a>.</p><h3 
id="Spring-Seealso">See also</h3><ul><li><a shape="rect" 
href="tutorial-jmsremoting.
 html">Spring JMS Tutorial</a></li><li><a shape="rect" 
href="creating-a-new-spring-based-camel-route.html">Creating a new Spring based 
Camel Route</a></li><li><a shape="rect" href="spring-example.html">Spring 
example</a></li><li><a shape="rect" href="xml-reference.html">Xml 
Reference</a></li><li><a shape="rect" 
href="advanced-configuration-of-camelcontext-using-spring.html">Advanced 
configuration of CamelContext using Spring</a></li><li><a shape="rect" 
href="how-do-i-import-routes-from-other-xml-files.html">How Do I Import Routes 
From Other XML Files?</a></li></ul></div>
+ return new Class[]{RouteA.class, RouteB.class}; 
+}]]></script>
+</div></div><p>&#160;</p><h3 id="Spring-UsingSpringXML">Using Spring 
XML</h3><p>You can use Spring 2.0 XML configuration to specify your <a 
shape="rect" href="xml-configuration.html">Xml Configuration</a> for <a 
shape="rect" href="routes.html">Routes</a> such as in the following <a 
shape="rect" class="external-link" 
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactory.xml";>example</a>.</p><div
 class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;camelContext id=&quot;camel-A&quot; 
xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
+  &lt;route&gt;
+    &lt;from uri=&quot;seda:start&quot;/&gt;
+    &lt;to uri=&quot;mock:result&quot;/&gt;
+  &lt;/route&gt;
+&lt;/camelContext&gt;]]></script>
+</div></div><p>&#160;</p><p><span style="font-size: 20.0px;">Configuring 
Components and Endpoints</span></p><p>You can configure your <a shape="rect" 
href="component.html">Component</a> or <a shape="rect" 
href="endpoint.html">Endpoint</a> instances in your <a shape="rect" 
href="spring.html">Spring</a> XML as follows in <a shape="rect" 
class="external-link" 
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/jmsRouteUsingSpring.xml";>this
 example</a>.</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;camelContext id=&quot;camel&quot; 
xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
+    &lt;jmxAgent id=&quot;agent&quot; disabled=&quot;true&quot;/&gt;
+&lt;/camelContext&gt;
+
+&lt;bean id=&quot;activemq&quot; 
class=&quot;org.apache.activemq.camel.component.ActiveMQComponent&quot;&gt;
+  &lt;property name=&quot;connectionFactory&quot;&gt;
+    &lt;bean 
class=&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;&gt;
+      &lt;property name=&quot;brokerURL&quot; 
value=&quot;vm://localhost?broker.persistent=false&amp;amp;broker.useJmx=false&quot;/&gt;
+    &lt;/bean&gt;
+  &lt;/property&gt;
+&lt;/bean&gt;]]></script>
+</div></div><p>&#160;</p><p>Which allows you to configure a component using 
some name (<strong><code>activemq</code></strong> in the above example), then 
you can refer to the component using 
<strong><code>activemq:[queue:|topic:]destinationName</code></strong>. This 
works by the&#160;<strong><code>SpringCamelContext</code></strong> lazily 
fetching components from the spring context for the scheme name you use for <a 
shape="rect" href="endpoint.html">Endpoint</a> <a shape="rect" 
href="uris.html">URIs</a>.</p><p>For more detail see <a shape="rect" 
href="how-do-i-configure-endpoints.html">Configuring Endpoints and 
Components</a>.</p><h2 id="Spring-SpringCacheIdempotentRepository">Spring Cache 
Idempotent Repository</h2><p>Available as of <strong>Camel 
2.17.1</strong></p><p>&#160;</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;bean id=&quot;repo&quot; 
class=&quot;org.apache.camel.spring.processor.idempotent.SpringCacheIdempotentRepository&quot;&gt;
+ &lt;constructor-arg&gt; 
+   &lt;bean 
class=&quot;org.springframework.cache.guava.GuavaCacheManager&quot;/&gt; 
+&lt;/constructor-arg&gt;
+ &lt;constructor-arg value=&quot;idempotent&quot;/&gt; 
+&lt;/bean&gt; 
+&lt;camelContext xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
+ &lt;route id=&quot;idempotent-cache&quot;&gt; 
+  &lt;from uri=&quot;direct:start&quot; /&gt; 
+    &lt;idempotentConsumer messageIdRepositoryRef=&quot;repo&quot; 
skipDuplicate=&quot;true&quot;&gt; 
+      &lt;header&gt;MessageId&lt;/header&gt; 
+      &lt;to 
uri=&quot;log:org.apache.camel.spring.processor.idempotent?level=INFO&amp;amp;showAll=true&amp;amp;multiline=true&quot;
 /&gt; &lt;to uri=&quot;mock:result&quot;/&gt;    
+    &lt;/idempotentConsumer&gt;
+ &lt;/route&gt;
+&lt;/camelContext&gt;]]></script>
+</div></div><p>&#160;</p><h3 
id="Spring-CamelContextAware">CamelContextAware</h3><p>If you want to be 
injected with the <a shape="rect" href="camelcontext.html">CamelContext</a> in 
your POJO just implement the <a shape="rect" class="external-link" 
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContextAware.html";>CamelContextAware
 interface</a>; then when Spring creates your POJO 
the&#160;<strong><code>CamelContext</code></strong> will be injected into your 
POJO. Also see the <a shape="rect" href="bean-integration.html">Bean 
Integration</a> for further injections.</p><h2 
id="Spring-IntegrationTesting">Integration Testing</h2><p>To avoid a hung route 
when testing using Spring Transactions see the note about Spring Integration 
Testing under&#160;<a shape="rect" 
href="transactional-client.html">Transactional Client</a>.</p><h3 
id="Spring-Seealso">See also</h3><ul><li><a shape="rect" 
href="tutorial-jmsremoting.html">Spring JMS Tutorial</a></li><li><a
  shape="rect" href="creating-a-new-spring-based-camel-route.html">Creating a 
new Spring based Camel Route</a></li><li><a shape="rect" 
href="spring-example.html">Spring example</a></li><li><a shape="rect" 
href="xml-reference.html">Xml Reference</a></li><li><a shape="rect" 
href="advanced-configuration-of-camelcontext-using-spring.html">Advanced 
configuration of CamelContext using Spring</a></li><li><a shape="rect" 
href="how-do-i-import-routes-from-other-xml-files.html">How Do I Import Routes 
From Other XML Files?</a></li></ul></div>
         </td>
         <td valign="top">
           <div class="navigation">


Reply via email to