You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jonathanq <jq...@abebooks.com> on 2010/04/30 20:36:49 UTC

Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

I am having serious issues with Camel 2.2.0 and Spring 3.0.2.RELEASE.

I am creating my route in spring as a bean and then injecting it into the
camelContext using the following:

  <camel:camelContext id="camel">
    <camel:routeBuilder ref="myRouteBuilderBean" />
  </camel:camelContext>

  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
    <property name="myProcessor" ref="myProcessorBean"/>
  </bean>

The actual route definition is:

  public void configure() throws Exception {
    from(getIncomingEndpoint())
            .convertBodyTo(String.class)
            .process(getMyProcessor());
  }

There are getters/setters on the endpoint and the processor.

The issue is that when camel starts up - it calls the "configure" on the
route builder BEFORE Spring has injected the bean with properties.

So the getIncomingEndpoint() returns null - which will later cause Camel to
fail saying you can't set a null uri (error:)

If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 - this
issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0 issue. 
It seems that Camel is trying to configure all of the routes before Spring
has actually injected the beans.

Note: the reason I am setting the value in Spring is that its actually
getting property-replaced.  However if you put a hardcoded string into
spring for the endpoint, its still not working.  So I know its not the
property replacement causing this.

Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not Spring
3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.

Any ideas? 

Thanks,

Jonathan

-- 
View this message in context: http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

Posted by Norman Maurer <no...@apache.org>.
I'm using camel 2.2.0 and spring 3.0 without any problem here.. Not
sure why you see this problem ? Could you double check that you don't
have old versions of spring mixed with the new ones in your classpath
?

Bye,
Norman


2010/5/11 Willem Jiang <wi...@gmail.com>:
> Claus Ibsen wrote:
>>
>> Hi
>>
>> Yeah implementing CamelContextAware should cause the bean to be
>> depends-on Camel automatically.
>> So I think a test should be created which doesn't implement this
>> interface.
>>
>
> I can't reproduce the issue by removing the CamelContextAware interface :(
>
> Willem
>
>>
>> On Tue, May 11, 2010 at 3:49 AM, Willem Jiang <wi...@gmail.com>
>> wrote:
>>>
>>> Hi Jonathan,
>>>
>>> I tried to reproduce the error that you meet, but no luck with with it.
>>>
>>> Can you past the stack trace and the code of your processor?
>>> Did you have any specify setting on your RouteBuilder ?
>>> They will help us to find the cause of issue.
>>>
>>>
>>> Willem
>>>
>>> jonathanq wrote:
>>>>
>>>> Hello,
>>>>
>>>> I grabbed the 2.3-SNAPSHOT jars and confirmed that my original issue is
>>>> still present in 2.3
>>>>
>>>> As with 2.2.0 - it can only be solved by specifying: depends-on="camel"
>>>> on
>>>> the route builder bean.
>>>>
>>>> I tried pulling the 2.3-SNAPSHOT code to run your test locally and
>>>> determine
>>>> what the difference is but I am having issues getting it to build
>>>> locally.
>>>>
>>>> In any event - I noticed one difference in that you implemented
>>>> "CamelContextAware" interface on the route builder.  And when
>>>> constructing
>>>> the route - you called a getter that used the URI and asked the
>>>> camelContext
>>>> for the endpoint.  I did the same in my test app and it did not solve
>>>> the
>>>> problem.
>>>>
>>>> I went back to an empty project and tried to create a bare-minimum
>>>> application that tried to replicate my issue.  And I was not able to
>>>> (ie:
>>>> it
>>>> worked as it should).
>>>> My only assumption is that when you have multiple beans chained together
>>>> -
>>>> that is when this issue shows up.
>>>>
>>>> I tried modifying the original application I encountered the issue and
>>>> when
>>>> I removed all other beans except for the routebuilder and a processor
>>>> definition (along with the endpoint uri).  That causes the issue.  If I
>>>> remove ref="myProcessor" from the routebuilder - it works fine.
>>>>
>>>> Yet the processor is just a simple object, implements processor and has
>>>> no
>>>> other dependencies.  I even duplicated this exactly in another project
>>>> and
>>>> I
>>>> was not able to reproduce this.
>>>>
>>>> I have a workaround at least - add depends-on="camel" to the
>>>> routebuilder.
>>>> Now the XML reads funny as the routebuilder bean depends on the
>>>> camelContext
>>>> - yet the camelContext has a reference to the routeBuilder.
>>>>
>>>> Thank you for your help.  I'll have to chalk this up to weird Spring
>>>> behavior I guess...
>>>>
>>>> Jonathan
>>>>
>>>>
>>>> willem.jiang wrote:
>>>>>
>>>>> Hi Jonathan,
>>>>>
>>>>> I just added a unit test[1] which is based on your test case, it looks
>>>>> like current camel 2.3 don't have the issue that you met.
>>>>>
>>>>> Can you have a look at my test and verify your case against the latest
>>>>> Camel 2.3-SNAPSHOT ?
>>>>>
>>>>> [1] http://svn.apache.org/viewvc?rev=942665&view=rev
>>>>>
>>>>> Willem
>>>>> jonathanq wrote:
>>>>>>
>>>>>> Claus,
>>>>>>
>>>>>> That worked!  I changed my spring configuration to to the one below
>>>>>> and
>>>>>> everything worked as expected.
>>>>>>
>>>>>>  <camel:camelContext id="camel">
>>>>>>   <camel:routeBuilder ref="myRouteBuilderBean" />
>>>>>>  </camel:camelContext>
>>>>>>
>>>>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder"
>>>>>> depends-on="camel">
>>>>>>   <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>>>>   <property name="myProcessor" ref="myProcessorBean"/>
>>>>>>  </bean>
>>>>>> Thanks for the help!
>>>>>>
>>>>>> Jonathan
>>>>>>
>>>>>>
>>>>>> Claus Ibsen-2 wrote:
>>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> Can you try with a depends-on="camel" attribute on the <bean> for the
>>>>>>> RouteBuilder to see if that helps.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Apr 30, 2010 at 8:36 PM, jonathanq <jq...@abebooks.com>
>>>>>>> wrote:
>>>>>>>>
>>>>>>>> I am having serious issues with Camel 2.2.0 and Spring
>>>>>>>> 3.0.2.RELEASE.
>>>>>>>>
>>>>>>>> I am creating my route in spring as a bean and then injecting it
>>>>>>>> into
>>>>>>>> the
>>>>>>>> camelContext using the following:
>>>>>>>>
>>>>>>>>  <camel:camelContext id="camel">
>>>>>>>>  <camel:routeBuilder ref="myRouteBuilderBean" />
>>>>>>>>  </camel:camelContext>
>>>>>>>>
>>>>>>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
>>>>>>>>  <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>>>>>>  <property name="myProcessor" ref="myProcessorBean"/>
>>>>>>>>  </bean>
>>>>>>>>
>>>>>>>> The actual route definition is:
>>>>>>>>
>>>>>>>>  public void configure() throws Exception {
>>>>>>>>  from(getIncomingEndpoint())
>>>>>>>>          .convertBodyTo(String.class)
>>>>>>>>          .process(getMyProcessor());
>>>>>>>>  }
>>>>>>>>
>>>>>>>> There are getters/setters on the endpoint and the processor.
>>>>>>>>
>>>>>>>> The issue is that when camel starts up - it calls the "configure" on
>>>>>>>> the
>>>>>>>> route builder BEFORE Spring has injected the bean with properties.
>>>>>>>>
>>>>>>>> So the getIncomingEndpoint() returns null - which will later cause
>>>>>>>> Camel
>>>>>>>> to
>>>>>>>> fail saying you can't set a null uri (error:)
>>>>>>>>
>>>>>>>> If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 -
>>>>>>>> this
>>>>>>>> issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0
>>>>>>>> issue.
>>>>>>>> It seems that Camel is trying to configure all of the routes before
>>>>>>>> Spring
>>>>>>>> has actually injected the beans.
>>>>>>>>
>>>>>>>> Note: the reason I am setting the value in Spring is that its
>>>>>>>> actually
>>>>>>>> getting property-replaced.  However if you put a hardcoded string
>>>>>>>> into
>>>>>>>> spring for the endpoint, its still not working.  So I know its not
>>>>>>>> the
>>>>>>>> property replacement causing this.
>>>>>>>>
>>>>>>>> Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not
>>>>>>>> Spring
>>>>>>>> 3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.
>>>>>>>>
>>>>>>>> Any ideas?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Jonathan
>>>>>>>>
>>>>>>>> --
>>>>>>>> View this message in context:
>>>>>>>>
>>>>>>>>
>>>>>>>> http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.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: Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

Posted by Willem Jiang <wi...@gmail.com>.
Claus Ibsen wrote:
> Hi
> 
> Yeah implementing CamelContextAware should cause the bean to be
> depends-on Camel automatically.
> So I think a test should be created which doesn't implement this interface.
> 

I can't reproduce the issue by removing the CamelContextAware interface :(

Willem

> 
> On Tue, May 11, 2010 at 3:49 AM, Willem Jiang <wi...@gmail.com> wrote:
>> Hi Jonathan,
>>
>> I tried to reproduce the error that you meet, but no luck with with it.
>>
>> Can you past the stack trace and the code of your processor?
>> Did you have any specify setting on your RouteBuilder ?
>> They will help us to find the cause of issue.
>>
>>
>> Willem
>>
>> jonathanq wrote:
>>> Hello,
>>>
>>> I grabbed the 2.3-SNAPSHOT jars and confirmed that my original issue is
>>> still present in 2.3
>>>
>>> As with 2.2.0 - it can only be solved by specifying: depends-on="camel" on
>>> the route builder bean.
>>>
>>> I tried pulling the 2.3-SNAPSHOT code to run your test locally and
>>> determine
>>> what the difference is but I am having issues getting it to build locally.
>>>
>>> In any event - I noticed one difference in that you implemented
>>> "CamelContextAware" interface on the route builder.  And when constructing
>>> the route - you called a getter that used the URI and asked the
>>> camelContext
>>> for the endpoint.  I did the same in my test app and it did not solve the
>>> problem.
>>>
>>> I went back to an empty project and tried to create a bare-minimum
>>> application that tried to replicate my issue.  And I was not able to (ie:
>>> it
>>> worked as it should).
>>> My only assumption is that when you have multiple beans chained together -
>>> that is when this issue shows up.
>>>
>>> I tried modifying the original application I encountered the issue and
>>> when
>>> I removed all other beans except for the routebuilder and a processor
>>> definition (along with the endpoint uri).  That causes the issue.  If I
>>> remove ref="myProcessor" from the routebuilder - it works fine.
>>>
>>> Yet the processor is just a simple object, implements processor and has no
>>> other dependencies.  I even duplicated this exactly in another project and
>>> I
>>> was not able to reproduce this.
>>>
>>> I have a workaround at least - add depends-on="camel" to the routebuilder.
>>> Now the XML reads funny as the routebuilder bean depends on the camelContext
>>> - yet the camelContext has a reference to the routeBuilder.
>>>
>>> Thank you for your help.  I'll have to chalk this up to weird Spring
>>> behavior I guess...
>>>
>>> Jonathan
>>>
>>>
>>> willem.jiang wrote:
>>>> Hi Jonathan,
>>>>
>>>> I just added a unit test[1] which is based on your test case, it looks
>>>> like current camel 2.3 don't have the issue that you met.
>>>>
>>>> Can you have a look at my test and verify your case against the latest
>>>> Camel 2.3-SNAPSHOT ?
>>>>
>>>> [1] http://svn.apache.org/viewvc?rev=942665&view=rev
>>>>
>>>> Willem
>>>> jonathanq wrote:
>>>>> Claus,
>>>>>
>>>>> That worked!  I changed my spring configuration to to the one below and
>>>>> everything worked as expected.
>>>>>
>>>>>  <camel:camelContext id="camel">
>>>>>    <camel:routeBuilder ref="myRouteBuilderBean" />
>>>>>  </camel:camelContext>
>>>>>
>>>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder"
>>>>> depends-on="camel">
>>>>>    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>>>    <property name="myProcessor" ref="myProcessorBean"/>
>>>>>  </bean>
>>>>> Thanks for the help!
>>>>>
>>>>> Jonathan
>>>>>
>>>>>
>>>>> Claus Ibsen-2 wrote:
>>>>>> Hi
>>>>>>
>>>>>> Can you try with a depends-on="camel" attribute on the <bean> for the
>>>>>> RouteBuilder to see if that helps.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Fri, Apr 30, 2010 at 8:36 PM, jonathanq <jq...@abebooks.com> wrote:
>>>>>>> I am having serious issues with Camel 2.2.0 and Spring 3.0.2.RELEASE.
>>>>>>>
>>>>>>> I am creating my route in spring as a bean and then injecting it into
>>>>>>> the
>>>>>>> camelContext using the following:
>>>>>>>
>>>>>>>  <camel:camelContext id="camel">
>>>>>>>   <camel:routeBuilder ref="myRouteBuilderBean" />
>>>>>>>  </camel:camelContext>
>>>>>>>
>>>>>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
>>>>>>>   <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>>>>>   <property name="myProcessor" ref="myProcessorBean"/>
>>>>>>>  </bean>
>>>>>>>
>>>>>>> The actual route definition is:
>>>>>>>
>>>>>>>  public void configure() throws Exception {
>>>>>>>   from(getIncomingEndpoint())
>>>>>>>           .convertBodyTo(String.class)
>>>>>>>           .process(getMyProcessor());
>>>>>>>  }
>>>>>>>
>>>>>>> There are getters/setters on the endpoint and the processor.
>>>>>>>
>>>>>>> The issue is that when camel starts up - it calls the "configure" on
>>>>>>> the
>>>>>>> route builder BEFORE Spring has injected the bean with properties.
>>>>>>>
>>>>>>> So the getIncomingEndpoint() returns null - which will later cause
>>>>>>> Camel
>>>>>>> to
>>>>>>> fail saying you can't set a null uri (error:)
>>>>>>>
>>>>>>> If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 -
>>>>>>> this
>>>>>>> issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0
>>>>>>> issue.
>>>>>>> It seems that Camel is trying to configure all of the routes before
>>>>>>> Spring
>>>>>>> has actually injected the beans.
>>>>>>>
>>>>>>> Note: the reason I am setting the value in Spring is that its actually
>>>>>>> getting property-replaced.  However if you put a hardcoded string into
>>>>>>> spring for the endpoint, its still not working.  So I know its not the
>>>>>>> property replacement causing this.
>>>>>>>
>>>>>>> Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not
>>>>>>> Spring
>>>>>>> 3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.
>>>>>>>
>>>>>>> Any ideas?
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Jonathan
>>>>>>>
>>>>>>> --
>>>>>>> View this message in context:
>>>>>>>
>>>>>>> http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.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: Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah implementing CamelContextAware should cause the bean to be
depends-on Camel automatically.
So I think a test should be created which doesn't implement this interface.


On Tue, May 11, 2010 at 3:49 AM, Willem Jiang <wi...@gmail.com> wrote:
> Hi Jonathan,
>
> I tried to reproduce the error that you meet, but no luck with with it.
>
> Can you past the stack trace and the code of your processor?
> Did you have any specify setting on your RouteBuilder ?
> They will help us to find the cause of issue.
>
>
> Willem
>
> jonathanq wrote:
>>
>> Hello,
>>
>> I grabbed the 2.3-SNAPSHOT jars and confirmed that my original issue is
>> still present in 2.3
>>
>> As with 2.2.0 - it can only be solved by specifying: depends-on="camel" on
>> the route builder bean.
>>
>> I tried pulling the 2.3-SNAPSHOT code to run your test locally and
>> determine
>> what the difference is but I am having issues getting it to build locally.
>>
>> In any event - I noticed one difference in that you implemented
>> "CamelContextAware" interface on the route builder.  And when constructing
>> the route - you called a getter that used the URI and asked the
>> camelContext
>> for the endpoint.  I did the same in my test app and it did not solve the
>> problem.
>>
>> I went back to an empty project and tried to create a bare-minimum
>> application that tried to replicate my issue.  And I was not able to (ie:
>> it
>> worked as it should).
>> My only assumption is that when you have multiple beans chained together -
>> that is when this issue shows up.
>>
>> I tried modifying the original application I encountered the issue and
>> when
>> I removed all other beans except for the routebuilder and a processor
>> definition (along with the endpoint uri).  That causes the issue.  If I
>> remove ref="myProcessor" from the routebuilder - it works fine.
>>
>> Yet the processor is just a simple object, implements processor and has no
>> other dependencies.  I even duplicated this exactly in another project and
>> I
>> was not able to reproduce this.
>>
>> I have a workaround at least - add depends-on="camel" to the routebuilder.
>> Now the XML reads funny as the routebuilder bean depends on the camelContext
>> - yet the camelContext has a reference to the routeBuilder.
>>
>> Thank you for your help.  I'll have to chalk this up to weird Spring
>> behavior I guess...
>>
>> Jonathan
>>
>>
>> willem.jiang wrote:
>>>
>>> Hi Jonathan,
>>>
>>> I just added a unit test[1] which is based on your test case, it looks
>>> like current camel 2.3 don't have the issue that you met.
>>>
>>> Can you have a look at my test and verify your case against the latest
>>> Camel 2.3-SNAPSHOT ?
>>>
>>> [1] http://svn.apache.org/viewvc?rev=942665&view=rev
>>>
>>> Willem
>>> jonathanq wrote:
>>>>
>>>> Claus,
>>>>
>>>> That worked!  I changed my spring configuration to to the one below and
>>>> everything worked as expected.
>>>>
>>>>  <camel:camelContext id="camel">
>>>>    <camel:routeBuilder ref="myRouteBuilderBean" />
>>>>  </camel:camelContext>
>>>>
>>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder"
>>>> depends-on="camel">
>>>>    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>>    <property name="myProcessor" ref="myProcessorBean"/>
>>>>  </bean>
>>>> Thanks for the help!
>>>>
>>>> Jonathan
>>>>
>>>>
>>>> Claus Ibsen-2 wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> Can you try with a depends-on="camel" attribute on the <bean> for the
>>>>> RouteBuilder to see if that helps.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Fri, Apr 30, 2010 at 8:36 PM, jonathanq <jq...@abebooks.com> wrote:
>>>>>>
>>>>>> I am having serious issues with Camel 2.2.0 and Spring 3.0.2.RELEASE.
>>>>>>
>>>>>> I am creating my route in spring as a bean and then injecting it into
>>>>>> the
>>>>>> camelContext using the following:
>>>>>>
>>>>>>  <camel:camelContext id="camel">
>>>>>>   <camel:routeBuilder ref="myRouteBuilderBean" />
>>>>>>  </camel:camelContext>
>>>>>>
>>>>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
>>>>>>   <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>>>>   <property name="myProcessor" ref="myProcessorBean"/>
>>>>>>  </bean>
>>>>>>
>>>>>> The actual route definition is:
>>>>>>
>>>>>>  public void configure() throws Exception {
>>>>>>   from(getIncomingEndpoint())
>>>>>>           .convertBodyTo(String.class)
>>>>>>           .process(getMyProcessor());
>>>>>>  }
>>>>>>
>>>>>> There are getters/setters on the endpoint and the processor.
>>>>>>
>>>>>> The issue is that when camel starts up - it calls the "configure" on
>>>>>> the
>>>>>> route builder BEFORE Spring has injected the bean with properties.
>>>>>>
>>>>>> So the getIncomingEndpoint() returns null - which will later cause
>>>>>> Camel
>>>>>> to
>>>>>> fail saying you can't set a null uri (error:)
>>>>>>
>>>>>> If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 -
>>>>>> this
>>>>>> issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0
>>>>>> issue.
>>>>>> It seems that Camel is trying to configure all of the routes before
>>>>>> Spring
>>>>>> has actually injected the beans.
>>>>>>
>>>>>> Note: the reason I am setting the value in Spring is that its actually
>>>>>> getting property-replaced.  However if you put a hardcoded string into
>>>>>> spring for the endpoint, its still not working.  So I know its not the
>>>>>> property replacement causing this.
>>>>>>
>>>>>> Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not
>>>>>> Spring
>>>>>> 3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.
>>>>>>
>>>>>> Any ideas?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Jonathan
>>>>>>
>>>>>> --
>>>>>> View this message in context:
>>>>>>
>>>>>> http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.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
>>>>>
>>>>>
>>>
>>>
>>
>
>



-- 
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: Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

Posted by Willem Jiang <wi...@gmail.com>.
Hi Jonathan,

I tried to reproduce the error that you meet, but no luck with with it.

Can you past the stack trace and the code of your processor?
Did you have any specify setting on your RouteBuilder ?
They will help us to find the cause of issue.


Willem

jonathanq wrote:
> Hello,
> 
> I grabbed the 2.3-SNAPSHOT jars and confirmed that my original issue is
> still present in 2.3
> 
> As with 2.2.0 - it can only be solved by specifying: depends-on="camel" on
> the route builder bean.
> 
> I tried pulling the 2.3-SNAPSHOT code to run your test locally and determine
> what the difference is but I am having issues getting it to build locally.  
> 
> In any event - I noticed one difference in that you implemented
> "CamelContextAware" interface on the route builder.  And when constructing
> the route - you called a getter that used the URI and asked the camelContext
> for the endpoint.  I did the same in my test app and it did not solve the
> problem.
> 
> I went back to an empty project and tried to create a bare-minimum
> application that tried to replicate my issue.  And I was not able to (ie: it
> worked as it should).  
> 
> My only assumption is that when you have multiple beans chained together -
> that is when this issue shows up.
> 
> I tried modifying the original application I encountered the issue and when
> I removed all other beans except for the routebuilder and a processor
> definition (along with the endpoint uri).  That causes the issue.  If I
> remove ref="myProcessor" from the routebuilder - it works fine.
> 
> Yet the processor is just a simple object, implements processor and has no
> other dependencies.  I even duplicated this exactly in another project and I
> was not able to reproduce this.
> 
> I have a workaround at least - add depends-on="camel" to the routebuilder. 
> Now the XML reads funny as the routebuilder bean depends on the camelContext
> - yet the camelContext has a reference to the routeBuilder.
> 
> Thank you for your help.  I'll have to chalk this up to weird Spring
> behavior I guess...
> 
> Jonathan
> 
> 
> willem.jiang wrote:
>> Hi Jonathan,
>>
>> I just added a unit test[1] which is based on your test case, it looks 
>> like current camel 2.3 don't have the issue that you met.
>>
>> Can you have a look at my test and verify your case against the latest 
>> Camel 2.3-SNAPSHOT ?
>>
>> [1] http://svn.apache.org/viewvc?rev=942665&view=rev
>>
>> Willem
>> jonathanq wrote:
>>> Claus,
>>>
>>> That worked!  I changed my spring configuration to to the one below and
>>> everything worked as expected.
>>>
>>>   <camel:camelContext id="camel">
>>>     <camel:routeBuilder ref="myRouteBuilderBean" />
>>>   </camel:camelContext>
>>>
>>>   <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder"
>>> depends-on="camel">
>>>     <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>     <property name="myProcessor" ref="myProcessorBean"/>
>>>   </bean> 
>>>
>>> Thanks for the help!
>>>
>>> Jonathan
>>>
>>>
>>> Claus Ibsen-2 wrote:
>>>> Hi
>>>>
>>>> Can you try with a depends-on="camel" attribute on the <bean> for the
>>>> RouteBuilder to see if that helps.
>>>>
>>>>
>>>>
>>>>
>>>> On Fri, Apr 30, 2010 at 8:36 PM, jonathanq <jq...@abebooks.com> wrote:
>>>>> I am having serious issues with Camel 2.2.0 and Spring 3.0.2.RELEASE.
>>>>>
>>>>> I am creating my route in spring as a bean and then injecting it into
>>>>> the
>>>>> camelContext using the following:
>>>>>
>>>>>  <camel:camelContext id="camel">
>>>>>    <camel:routeBuilder ref="myRouteBuilderBean" />
>>>>>  </camel:camelContext>
>>>>>
>>>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
>>>>>    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>>>    <property name="myProcessor" ref="myProcessorBean"/>
>>>>>  </bean>
>>>>>
>>>>> The actual route definition is:
>>>>>
>>>>>  public void configure() throws Exception {
>>>>>    from(getIncomingEndpoint())
>>>>>            .convertBodyTo(String.class)
>>>>>            .process(getMyProcessor());
>>>>>  }
>>>>>
>>>>> There are getters/setters on the endpoint and the processor.
>>>>>
>>>>> The issue is that when camel starts up - it calls the "configure" on
>>>>> the
>>>>> route builder BEFORE Spring has injected the bean with properties.
>>>>>
>>>>> So the getIncomingEndpoint() returns null - which will later cause
>>>>> Camel
>>>>> to
>>>>> fail saying you can't set a null uri (error:)
>>>>>
>>>>> If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 - this
>>>>> issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0
>>>>> issue.
>>>>> It seems that Camel is trying to configure all of the routes before
>>>>> Spring
>>>>> has actually injected the beans.
>>>>>
>>>>> Note: the reason I am setting the value in Spring is that its actually
>>>>> getting property-replaced.  However if you put a hardcoded string into
>>>>> spring for the endpoint, its still not working.  So I know its not the
>>>>> property replacement causing this.
>>>>>
>>>>> Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not
>>>>> Spring
>>>>> 3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.
>>>>>
>>>>> Any ideas?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Jonathan
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.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: Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

Posted by jonathanq <jq...@abebooks.com>.
Hello,

I grabbed the 2.3-SNAPSHOT jars and confirmed that my original issue is
still present in 2.3

As with 2.2.0 - it can only be solved by specifying: depends-on="camel" on
the route builder bean.

I tried pulling the 2.3-SNAPSHOT code to run your test locally and determine
what the difference is but I am having issues getting it to build locally.  

In any event - I noticed one difference in that you implemented
"CamelContextAware" interface on the route builder.  And when constructing
the route - you called a getter that used the URI and asked the camelContext
for the endpoint.  I did the same in my test app and it did not solve the
problem.

I went back to an empty project and tried to create a bare-minimum
application that tried to replicate my issue.  And I was not able to (ie: it
worked as it should).  

My only assumption is that when you have multiple beans chained together -
that is when this issue shows up.

I tried modifying the original application I encountered the issue and when
I removed all other beans except for the routebuilder and a processor
definition (along with the endpoint uri).  That causes the issue.  If I
remove ref="myProcessor" from the routebuilder - it works fine.

Yet the processor is just a simple object, implements processor and has no
other dependencies.  I even duplicated this exactly in another project and I
was not able to reproduce this.

I have a workaround at least - add depends-on="camel" to the routebuilder. 
Now the XML reads funny as the routebuilder bean depends on the camelContext
- yet the camelContext has a reference to the routeBuilder.

Thank you for your help.  I'll have to chalk this up to weird Spring
behavior I guess...

Jonathan


willem.jiang wrote:
> 
> Hi Jonathan,
> 
> I just added a unit test[1] which is based on your test case, it looks 
> like current camel 2.3 don't have the issue that you met.
> 
> Can you have a look at my test and verify your case against the latest 
> Camel 2.3-SNAPSHOT ?
> 
> [1] http://svn.apache.org/viewvc?rev=942665&view=rev
> 
> Willem
> jonathanq wrote:
>> Claus,
>> 
>> That worked!  I changed my spring configuration to to the one below and
>> everything worked as expected.
>> 
>>   <camel:camelContext id="camel">
>>     <camel:routeBuilder ref="myRouteBuilderBean" />
>>   </camel:camelContext>
>> 
>>   <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder"
>> depends-on="camel">
>>     <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>     <property name="myProcessor" ref="myProcessorBean"/>
>>   </bean> 
>> 
>> Thanks for the help!
>> 
>> Jonathan
>> 
>> 
>> Claus Ibsen-2 wrote:
>>> Hi
>>>
>>> Can you try with a depends-on="camel" attribute on the <bean> for the
>>> RouteBuilder to see if that helps.
>>>
>>>
>>>
>>>
>>> On Fri, Apr 30, 2010 at 8:36 PM, jonathanq <jq...@abebooks.com> wrote:
>>>> I am having serious issues with Camel 2.2.0 and Spring 3.0.2.RELEASE.
>>>>
>>>> I am creating my route in spring as a bean and then injecting it into
>>>> the
>>>> camelContext using the following:
>>>>
>>>>  <camel:camelContext id="camel">
>>>>    <camel:routeBuilder ref="myRouteBuilderBean" />
>>>>  </camel:camelContext>
>>>>
>>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
>>>>    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>>    <property name="myProcessor" ref="myProcessorBean"/>
>>>>  </bean>
>>>>
>>>> The actual route definition is:
>>>>
>>>>  public void configure() throws Exception {
>>>>    from(getIncomingEndpoint())
>>>>            .convertBodyTo(String.class)
>>>>            .process(getMyProcessor());
>>>>  }
>>>>
>>>> There are getters/setters on the endpoint and the processor.
>>>>
>>>> The issue is that when camel starts up - it calls the "configure" on
>>>> the
>>>> route builder BEFORE Spring has injected the bean with properties.
>>>>
>>>> So the getIncomingEndpoint() returns null - which will later cause
>>>> Camel
>>>> to
>>>> fail saying you can't set a null uri (error:)
>>>>
>>>> If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 - this
>>>> issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0
>>>> issue.
>>>> It seems that Camel is trying to configure all of the routes before
>>>> Spring
>>>> has actually injected the beans.
>>>>
>>>> Note: the reason I am setting the value in Spring is that its actually
>>>> getting property-replaced.  However if you put a hardcoded string into
>>>> spring for the endpoint, its still not working.  So I know its not the
>>>> property replacement causing this.
>>>>
>>>> Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not
>>>> Spring
>>>> 3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.
>>>>
>>>> Any ideas?
>>>>
>>>> Thanks,
>>>>
>>>> Jonathan
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.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
>>>
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28517592.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

Posted by Willem Jiang <wi...@gmail.com>.
Hi Jonathan,

I just added a unit test[1] which is based on your test case, it looks 
like current camel 2.3 don't have the issue that you met.

Can you have a look at my test and verify your case against the latest 
Camel 2.3-SNAPSHOT ?

[1] http://svn.apache.org/viewvc?rev=942665&view=rev

Willem
jonathanq wrote:
> Claus,
> 
> That worked!  I changed my spring configuration to to the one below and
> everything worked as expected.
> 
>   <camel:camelContext id="camel">
>     <camel:routeBuilder ref="myRouteBuilderBean" />
>   </camel:camelContext>
> 
>   <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder"
> depends-on="camel">
>     <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>     <property name="myProcessor" ref="myProcessorBean"/>
>   </bean> 
> 
> Thanks for the help!
> 
> Jonathan
> 
> 
> Claus Ibsen-2 wrote:
>> Hi
>>
>> Can you try with a depends-on="camel" attribute on the <bean> for the
>> RouteBuilder to see if that helps.
>>
>>
>>
>>
>> On Fri, Apr 30, 2010 at 8:36 PM, jonathanq <jq...@abebooks.com> wrote:
>>> I am having serious issues with Camel 2.2.0 and Spring 3.0.2.RELEASE.
>>>
>>> I am creating my route in spring as a bean and then injecting it into the
>>> camelContext using the following:
>>>
>>>  <camel:camelContext id="camel">
>>>    <camel:routeBuilder ref="myRouteBuilderBean" />
>>>  </camel:camelContext>
>>>
>>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
>>>    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>>    <property name="myProcessor" ref="myProcessorBean"/>
>>>  </bean>
>>>
>>> The actual route definition is:
>>>
>>>  public void configure() throws Exception {
>>>    from(getIncomingEndpoint())
>>>            .convertBodyTo(String.class)
>>>            .process(getMyProcessor());
>>>  }
>>>
>>> There are getters/setters on the endpoint and the processor.
>>>
>>> The issue is that when camel starts up - it calls the "configure" on the
>>> route builder BEFORE Spring has injected the bean with properties.
>>>
>>> So the getIncomingEndpoint() returns null - which will later cause Camel
>>> to
>>> fail saying you can't set a null uri (error:)
>>>
>>> If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 - this
>>> issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0
>>> issue.
>>> It seems that Camel is trying to configure all of the routes before
>>> Spring
>>> has actually injected the beans.
>>>
>>> Note: the reason I am setting the value in Spring is that its actually
>>> getting property-replaced.  However if you put a hardcoded string into
>>> spring for the endpoint, its still not working.  So I know its not the
>>> property replacement causing this.
>>>
>>> Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not Spring
>>> 3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.
>>>
>>> Any ideas?
>>>
>>> Thanks,
>>>
>>> Jonathan
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.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: Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

Posted by jonathanq <jq...@abebooks.com>.
Claus,

That worked!  I changed my spring configuration to to the one below and
everything worked as expected.

  <camel:camelContext id="camel">
    <camel:routeBuilder ref="myRouteBuilderBean" />
  </camel:camelContext>

  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder"
depends-on="camel">
    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
    <property name="myProcessor" ref="myProcessorBean"/>
  </bean> 

Thanks for the help!

Jonathan


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Can you try with a depends-on="camel" attribute on the <bean> for the
> RouteBuilder to see if that helps.
> 
> 
> 
> 
> On Fri, Apr 30, 2010 at 8:36 PM, jonathanq <jq...@abebooks.com> wrote:
>>
>> I am having serious issues with Camel 2.2.0 and Spring 3.0.2.RELEASE.
>>
>> I am creating my route in spring as a bean and then injecting it into the
>> camelContext using the following:
>>
>>  <camel:camelContext id="camel">
>>    <camel:routeBuilder ref="myRouteBuilderBean" />
>>  </camel:camelContext>
>>
>>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
>>    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>>    <property name="myProcessor" ref="myProcessorBean"/>
>>  </bean>
>>
>> The actual route definition is:
>>
>>  public void configure() throws Exception {
>>    from(getIncomingEndpoint())
>>            .convertBodyTo(String.class)
>>            .process(getMyProcessor());
>>  }
>>
>> There are getters/setters on the endpoint and the processor.
>>
>> The issue is that when camel starts up - it calls the "configure" on the
>> route builder BEFORE Spring has injected the bean with properties.
>>
>> So the getIncomingEndpoint() returns null - which will later cause Camel
>> to
>> fail saying you can't set a null uri (error:)
>>
>> If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 - this
>> issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0
>> issue.
>> It seems that Camel is trying to configure all of the routes before
>> Spring
>> has actually injected the beans.
>>
>> Note: the reason I am setting the value in Spring is that its actually
>> getting property-replaced.  However if you put a hardcoded string into
>> spring for the endpoint, its still not working.  So I know its not the
>> property replacement causing this.
>>
>> Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not Spring
>> 3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.
>>
>> Any ideas?
>>
>> Thanks,
>>
>> Jonathan
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.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
> 
> 

-- 
View this message in context: http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28436749.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Spring 3.0 and Camel 2.2 - Route configure() called before Spring beans injected

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Can you try with a depends-on="camel" attribute on the <bean> for the
RouteBuilder to see if that helps.




On Fri, Apr 30, 2010 at 8:36 PM, jonathanq <jq...@abebooks.com> wrote:
>
> I am having serious issues with Camel 2.2.0 and Spring 3.0.2.RELEASE.
>
> I am creating my route in spring as a bean and then injecting it into the
> camelContext using the following:
>
>  <camel:camelContext id="camel">
>    <camel:routeBuilder ref="myRouteBuilderBean" />
>  </camel:camelContext>
>
>  <bean id="myRouteBuilderBean" class="com.example.MyRouteBuilder">
>    <property name="incomingEndpoint" value="file://C:\\triggerdir\\"/>
>    <property name="myProcessor" ref="myProcessorBean"/>
>  </bean>
>
> The actual route definition is:
>
>  public void configure() throws Exception {
>    from(getIncomingEndpoint())
>            .convertBodyTo(String.class)
>            .process(getMyProcessor());
>  }
>
> There are getters/setters on the endpoint and the processor.
>
> The issue is that when camel starts up - it calls the "configure" on the
> route builder BEFORE Spring has injected the bean with properties.
>
> So the getIncomingEndpoint() returns null - which will later cause Camel to
> fail saying you can't set a null uri (error:)
>
> If I change from using Spring 3.0.2.RELEASE to Spring 2.5.6.SR01 - this
> issues goes away.  So it is definitely a camel 2.2.0 and Spring 3.0 issue.
> It seems that Camel is trying to configure all of the routes before Spring
> has actually injected the beans.
>
> Note: the reason I am setting the value in Spring is that its actually
> getting property-replaced.  However if you put a hardcoded string into
> spring for the endpoint, its still not working.  So I know its not the
> property replacement causing this.
>
> Like I said - works fine in Spring 2.5.6 and Camel 2.2.0 - but not Spring
> 3.0.0.RELEASE, 3.0.1.RELEASE or 3.0.2.RELEASE.
>
> Any ideas?
>
> Thanks,
>
> Jonathan
>
> --
> View this message in context: http://old.nabble.com/Spring-3.0-and-Camel-2.2---Route-configure%28%29-called-before-Spring-beans-injected-tp28415437p28415437.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