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 <strong>Camel 2.15</strong>: Cam
el supports Spring Boot using the <code><a shape="rect"
href="spring-boot.html">camel-spring-boot</a></code>
component.</li><li>From <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 <strong><code>CamelContext</code></strong> inside
any <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><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 <strong>Camel 2.15</strong>: Cam
el supports Spring Boot using the <code><a shape="rect"
href="spring-boot.html">camel-spring-boot</a></code>
component.</li><li>From <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 <strong><code>CamelContext</code></strong> inside
any <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[<beans
xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ 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
+ ">]]></script>
+</div></div><p> </p><h4
id="Spring-Usingcamel:Namespace">Using <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="http://camel.apache.org/schema/spring"]]></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[<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"
+ xsi:schemaLocation="
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">
-</plain-text-body><h4
id="Spring-Usingcamel:Namespace">Using <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 <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<package>">Using <code><package></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 <strong><code><package></package></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>
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <package>org.apache.camel.spring.config.scan.route</package>
- </camelContext>
-</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 <strong><code><package></code></strong>
and <strong><code><packageScan></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><routeBuilder
ref="theBeanId"/></code></strong> or the
<strong><code><contextScan></code></strong>
feature.</p></rich-text-body><h4
id="Spring-Using<packageScan>">Using <code><packageScan></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 <strong><code><packageScan/></code></strong>
tag. The tag must contain one or
more <strong><code>package</code></strong> elements (similar to
<strong><code>1.x</code></strong>), and optionally one or
more <strong><code>includes</code></strong>
or <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>
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <packageScan>
- <package>org.example.routes</package>
- <excludes>**.*Excluded*</excludes>
- <includes>**.*</includes>
- </packageScan>
- </camelContext>
-</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 <strong><code>org.example.routes</code></strong> package
and any subpackages for <strong><code>RouteBuilder</code></strong>
classes. Say the scan finds two <strong><code>RouteBuilders</code></strong>,
one in <strong><code>org.example.routes</code></strong>
called <strong><code>MyRoute</code></strong> and
another <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>, <strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong>
) and the include and exclude patterns are applied.</p><p>The exclude
pattern <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>, <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>, <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 <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><component-scan></code></strong> feature and have Camel
pickup any <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">
- @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><packageScan></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 <strong><code>routes-context.xml</code></strong> and three Route
builders <strong><code>RouteA</code>, </strong><code>RouteB</code>
and <strong><code>RouteC</code></strong> in
the <strong><code>org.example.routes</code></strong> package.
The <strong><code>packageScan</code></strong> definition would discover
all three of these routes and initialize
them.</p><p>Say <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 <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 <strong><code>camelContext</code></strong> initialization by spring to
exclude the <strong><code>MyExcludedRouteBuilder.class</code></strong> we
need to intercept the spring context creation. When
overriding <strong><code>createApplicationContext</code></strong> to
create the spring context, we call
the <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 <strong><code>RouteB</code></strong>
and <strong><code>RouteA</code></strong> by
overriding:</p><plain-text-body>@Override
+]]></script>
+</div></div><p>... and then use the <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[<camel:camelContext
id="camel5">
+ <camel:package>org.apache.camel.spring.example</camel:package>
+</camel:camelContext>
+]]></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[<camelContext id="camel5"
xmlns="http://camel.apache.org/schema/spring">
+ <routeBuilder ref="myBuilder" />
+</camelContext>
+
+<bean id="myBuilder"
class="org.apache.camel.spring.example.test1.MyRouteBuilder"/>]]></script>
+</div></div><h4
id="Spring-Using<package>">Using <code><package></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 <strong><code><package></package></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[<camel:camelContext
id="camel5">
+ <camel:package>org.apache.camel.spring.example</camel:package>
+</camel:camelContext>]]></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 <strong><code><package></code></strong>
and <strong><code><packageScan></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><routeBuilder
ref="theBeanId"/></code></strong> or the
<strong><code><contextScan></code></strong> feature.</p><h4
id="Spring-Using<packageScan>">Using <code><packageScan></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 <s
trong><code><packageScan/></code></strong> tag. The tag must contain one
or more <strong><code>package</code></strong> elements (similar to
<strong><code>1.x</code></strong>), and optionally one or
more <strong><code>includes</code></strong>
or <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[<camelContext
xmlns="http://camel.apache.org/schema/spring">
+ <packageScan>
+ <package>org.example.routes</package>
+ <excludes>**.*Excluded*</excludes>
+ <includes>**.*</includes>
+ </packageScan>
+</camelContext>]]></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 <strong><code>org.example.routes</code></strong> package and any
subpackages for <strong><code>RouteBuilder</code></strong> classes. Say
the scan finds two <strong><code>RouteBuilders</code></strong>, one
in <strong><code>org.example.routes</code></strong>
called <strong><code>MyRoute</code></strong> and
another <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>, <strong><code>org.example.routes.excluded.MyExcludedRoute</code></strong>
) and the include and exclude patterns are applied.</p><p>The exclude
pattern <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>, <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>, <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 <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><component-scan></code></strong> feature and have Camel
pickup any <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[<!-- enable Spring @Component scan -->
+<context:component-scan
base-package="org.apache.camel.spring.issues.contextscan"/>
+
+<camelContext xmlns="http://camel.apache.org/schema/spring">
+ <!-- and then let Camel use those @Component scanned route builders
-->
+ <contextScan/>
+</camelContext>]]></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("direct:start") .to("mock:result");
+ }
+}]]></script>
+</div></div><p> </p><p>You can also use the ANT style for inclusion and
exclusion, as mentioned above in the
<strong><code><packageScan></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 <strong><code>routes-context.xml</code></strong> and three Route
builders <strong><code>RouteA</code>, </strong><code>RouteB</code>
and <strong><code>RouteC</code></strong> in
the <strong><code>org.example.routes</code></strong> package.
The <strong><code>packageScan</code></strong> definition would discover
all three of these routes and initialize
them.</p><p>Say <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 <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 <strong><code>camelContext</code></strong> initialization by spring to
exclude the <strong><code>MyExcludedRouteBuilder.class</code></strong> we
need to intercept the spring context creation. When
overriding <strong><code>createApplicationContext</code></strong> to
create the spring context, we call
the <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[] {"routes-context.xml"},
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 <strong><code>RouteB</code></strong>
and <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 <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><bean id="repo"
class="org.apache.camel.spring.processor.idempotent.SpringCacheIdempotentRepository">
- <constructor-arg>
- <bean class="org.springframework.cache.guava.GuavaCacheManager"/>
- </constructor-arg>
- <constructor-arg value="idempotent"/>
-</bean>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route id="idempotent-cache">
- <from uri="direct:start" />
- <idempotentConsumer messageIdRepositoryRef="repo"
skipDuplicate="true">
- <header>MessageId</header>
- <to
uri="log:org.apache.camel.spring.processor.idempotent?level=INFO&amp;showAll=true&amp;multiline=true"
/>
- <to uri="mock:result"/>
- </idempotentConsumer>
- </route>
-</camelContext></plain-text-body><p> </p><p> </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 <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 <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> </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[<camelContext id="camel-A"
xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="seda:start"/>
+ <to uri="mock:result"/>
+ </route>
+</camelContext>]]></script>
+</div></div><p> </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[<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
+ <jmxAgent id="agent" disabled="true"/>
+</camelContext>
+
+<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
+ <property name="connectionFactory">
+ <bean
class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL"
value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
+ </bean>
+ </property>
+</bean>]]></script>
+</div></div><p> </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 <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> </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[<bean id="repo"
class="org.apache.camel.spring.processor.idempotent.SpringCacheIdempotentRepository">
+ <constructor-arg>
+ <bean
class="org.springframework.cache.guava.GuavaCacheManager"/>
+</constructor-arg>
+ <constructor-arg value="idempotent"/>
+</bean>
+<camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route id="idempotent-cache">
+ <from uri="direct:start" />
+ <idempotentConsumer messageIdRepositoryRef="repo"
skipDuplicate="true">
+ <header>MessageId</header>
+ <to
uri="log:org.apache.camel.spring.processor.idempotent?level=INFO&amp;showAll=true&amp;multiline=true"
/> <to uri="mock:result"/>
+ </idempotentConsumer>
+ </route>
+</camelContext>]]></script>
+</div></div><p> </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 <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 <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">