activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject Re: [camel] Spring and Custom Components
Date Thu, 10 May 2007 15:27:33 GMT
Hi Jeff

On 5/9/07, Jeff Gunther <> wrote:
> Hi All,
> Here is the code snippet I'm working to configure in Spring:
> final CamelContext container = new DefaultCamelContext();
> container.addComponent("foo", new FooComponent(container));

FWIW if you don't need to explicitly configure the FooComponent
directly if it doesn't have much configuration data - you can create a
file called


with contents


(you can add other property configurations in there too if you like)

Then if you refer to an endpoint as "foo://somethingOrOther" Camel
will auto-discover your component and register it.

The downside of this approach though is if FooComponent needs some
actual injection; like a DataSource or whatever. You can configure
endpoints in a few different ways...

One thing thats not quite tested or documented yet that I wanted was
the ability to use the Injector on a CamelContext to dependency inject
the FooComponent (using either autowire mode in Spring or using
@Resource type dependency injection) so that you don't have to
explicitly add the FooComponent to the Spring XML, you just need to
add the resources which need to be injected into the FooComponent.
(This also has the nice benefit of avoiding component developers
having to worry about writing Spring XML namespace handler stuff)

> I'm using the Spring 2.0 XML Namespaces approach to define my routes.
> How can I add a custom component to a "camelContext"?

If after my long ramble above you still want to explicitly have a
<fooComponent cheese="edam"/> type XML within the <camelContext/> then
you need to do some Spring XML NamespaceHandler hacking - which is
kinda ugly & crufty work unfortunately. You could use xbean-spring
which tries to automate most of this work for you.

If you look in camel-spring at CamelNamespaceHandler you'll see how we
handle the Spring XML stuff (warning its kinda hairy code to look at).
If you wanted <fooComponent> to be a standard part of the core Camel
schema then you'd hack that file to add your component & add a patch
to the camel XSD. Otherwise you could write your own namespace &
schema if you prefer.

Incidentally I've updated the website with more details

View raw message