You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by greenstar <jn...@gmail.com> on 2010/04/01 23:00:57 UTC

Camel, Spring and Initialization

I am using Camel with Spring like follows:

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <routeBuilder ref="routeBuilder1"/>
    ...
</camelContext>

I'm looking for a way to run some code before the route builders are run. 
This seems like it should be straightforward.  I've tried the @PostConstruct
(with CommonAnnotationBeanPostProcessor).  I've also tried
ApplicationContextEvent.  These initialization hooks all work, but they are
all executed *after* the RouteBuilder.configure() methods are called.

How does the <camelContext> tag integrate into Spring and how can I specify
the initialization order of my own beans relative to it?

Thanks.
-- 
View this message in context: http://old.nabble.com/Camel%2C-Spring-and-Initialization-tp28113566p28113566.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel, Spring and Initialization

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Apr 1, 2010 at 11:00 PM, greenstar <jn...@gmail.com> wrote:
>
> I am using Camel with Spring like follows:
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>    <routeBuilder ref="routeBuilder1"/>
>    ...
> </camelContext>
>
> I'm looking for a way to run some code before the route builders are run.
> This seems like it should be straightforward.  I've tried the @PostConstruct
> (with CommonAnnotationBeanPostProcessor).  I've also tried
> ApplicationContextEvent.  These initialization hooks all work, but they are
> all executed *after* the RouteBuilder.configure() methods are called.
>
> How does the <camelContext> tag integrate into Spring and how can I specify
> the initialization order of my own beans relative to it?
>

I am looking into this but I think you can maybe use depends-on the
route builder bean as shown here:

    <bean id="myRouteBuilder" depends-on="myDependsOnBean"
class="org.apache.camel.spring.config.MyDependsOnRouteBuilder"/>

    <!-- this bean must be initialized first -->
    <bean id="myDependsOnBean"
class="org.apache.camel.spring.config.MyDependsOnBean">
        <property name="endpointName" value="mock:result"/>
    </bean>

    <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
        <routeBuilder ref="myRouteBuilder"/>
    </camelContext>



> Thanks.
> --
> View this message in context: http://old.nabble.com/Camel%2C-Spring-and-Initialization-tp28113566p28113566.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Camel, Spring and Initialization

Posted by greenstar <jn...@gmail.com>.

Claus Ibsen-2 wrote:
> 
> Could you create a ticket in JIRA to add depends-on attribute to
> <camelContext/> tag.
> 

Done: https://issues.apache.org/activemq/browse/CAMEL-2610

Thanks.

-- 
View this message in context: http://old.nabble.com/Camel%2C-Spring-and-Initialization-tp28113566p28120946.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel, Spring and Initialization

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Apr 2, 2010 at 4:48 PM, greenstar <jn...@gmail.com> wrote:
>
>
> Claus Ibsen-2 wrote:
>>
>> The code to run before is that in the RouteBuilder class? Or is it
>> defined as a spring bean etc.?
>>
>
> It's defined as a spring bean.  It can't practically go in the RouteBuilder
> because there are several routes which require this initialization.

Hi

Could you create a ticket in JIRA to add depends-on attribute to
<camelContext/> tag.


> --
> View this message in context: http://old.nabble.com/Camel%2C-Spring-and-Initialization-tp28113566p28119764.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Camel, Spring and Initialization

Posted by greenstar <jn...@gmail.com>.

Claus Ibsen-2 wrote:
> 
> The code to run before is that in the RouteBuilder class? Or is it
> defined as a spring bean etc.?
> 

It's defined as a spring bean.  It can't practically go in the RouteBuilder
because there are several routes which require this initialization.
-- 
View this message in context: http://old.nabble.com/Camel%2C-Spring-and-Initialization-tp28113566p28119764.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel, Spring and Initialization

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Apr 1, 2010 at 11:00 PM, greenstar <jn...@gmail.com> wrote:
>
> I am using Camel with Spring like follows:
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
>    <routeBuilder ref="routeBuilder1"/>
>    ...
> </camelContext>
>
> I'm looking for a way to run some code before the route builders are run.
> This seems like it should be straightforward.  I've tried the @PostConstruct
> (with CommonAnnotationBeanPostProcessor).  I've also tried
> ApplicationContextEvent.  These initialization hooks all work, but they are
> all executed *after* the RouteBuilder.configure() methods are called.
>

The code to run before is that in the RouteBuilder class? Or is it
defined as a spring bean etc.?


> How does the <camelContext> tag integrate into Spring and how can I specify
> the initialization order of my own beans relative to it?
>

In Spring XML you can use the depends-on attribute in the <bean> tag.

I wonder if we need to add it to <camelContext> as well so you can
have Camel depend upon other beans.


> Thanks.
> --
> View this message in context: http://old.nabble.com/Camel%2C-Spring-and-Initialization-tp28113566p28113566.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus