camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <>
Subject [jira] [Resolved] (CAMEL-6463) Camel routes added to context at wrong point of Spring lifecycle
Date Tue, 23 Jul 2013 07:20:57 GMT


Claus Ibsen resolved CAMEL-6463.

       Resolution: Fixed
    Fix Version/s: 2.12.0

Thanks for reporting and providing a solution.

This has been introduced from Camel 2.12 onwards, as we want to leave the existing releases
with current behavior.
> Camel routes added to context at wrong point of Spring lifecycle
> ----------------------------------------------------------------
>                 Key: CAMEL-6463
>                 URL:
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.9.2
>         Environment: Not relevant.
>            Reporter: Daniel Cook
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 2.12.0
> We use camel with Java DSL and a lot of spring dependency injection, we context scan
to find the Route Builders.
> We have an intermittent problem where camel cannot start due to a null reference being
thrown by a route.  Example code (for illustrative purposes) is:
> public class MyRouteBuilder extends RouteBuilder {
> @Autowired
> private MyService myService;
> @Override
> public void configure() throws Exception {
>     from(ENDPOINT)
>     .process(myService)
> }
> }
> In the example above occassionally there is a .process(NULL) reference error thrown at
runtime; usually only on quick machines.  I stress this is not a problem with our Spring Dependency
injection config.
> After looking at the camel code, including on master, the problem arrises because the
AbstractCamelContextFactoryBean (which the Spring CamelContextFactoryBean extends) installs
the routes (calling the route builder's configure() method) into the context in the afterPropertiesSet()
method.  There is no guarantee that spring will have initialised the service as the Spring
Camel Context does not depend on the bean.  The routes should be installed when spring indicates
everything has been initialised, a ContextRefreshed event.
> The workaround is not to autowire services used in routes but 'new' them.  

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message