How to inject multiple endpoint in SEI using Camel's @EndpointInject

By default you can inject annotation on single method of an interface like:

public interface MyListener {


    String sayHello(String name);


what if you need multiple methods like this with @EndpointInjection happening over them for each endpoint e.g.:

public interface MyListener {


    String sayHelloFoo(String name);


    String sayHelloBar(String name);


The simple solution i have working involved spring's FactoryBean implementation.

It need following steps:

<!-- Define route for which you need injection to happen -->

<bean id="r" class="MyListener" />

<!-- Define producer template having that route  -->  

<camelContext  xmlns="">

        <template id="producerTemplate" />

        <routeBuilder ref="r"/>


 <!-- define FactoryBean for proxy instance --> 

<bean id="definedCamel" class="CamelFactoryBean">

        <constructor-arg index="0" value="MyListener" />

        <constructor-arg index="1" ref="producerTemplate" />


The FactoryBean will create instance of custom InvocationHandler and return it which will invoke the endpoint on the ProducerTemplate instance.


Popular posts from this blog Connection reset

Spring: implements interface not working in @Controller

Hide empty last column from Table/Tree Viewer