...
Warning |
---|
Use caution when specifying the package name as |
Info | ||
---|---|---|
| ||
The <package> and <packageScan> 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 |
Using <packageScan>
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 <packageScan/> 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.
...
**.??cluded* would match org.simple.IncludedRoute, org.simple.Excluded but not match org.simple.PrecludedRoute
Using contextScan
Available as of Camel 2.4
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 <component-scan>
feature and have Camel pickup any RouteBuilder instances which was created by Spring in its scan process.
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/contextscan/SpringRouteIsComponentAnnotatedTest.xml} |
This allows you to just annotate your routes using the Spring @Component
and have those routes included by Camel
Code Block |
---|
@Component
public class MyRoute extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
from("direct:start").to("mock:result");
}
}
|
You can also use the ANT style for inclusion and exclusion, as mentioned above in the <packageScan>
documentation.
Test time exclusion.
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.
...