You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Daniel Cook (JIRA)" <ji...@apache.org> on 2013/06/17 13:21:21 UTC

[jira] [Created] (CAMEL-6463) Camel routes added to context at wrong point of Spring lifecycle

Daniel Cook created CAMEL-6463:
----------------------------------

             Summary: Camel routes added to context at wrong point of Spring lifecycle
                 Key: CAMEL-6463
                 URL: https://issues.apache.org/jira/browse/CAMEL-6463
             Project: Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 2.9.2
         Environment: Not relevant.
            Reporter: Daniel Cook
            Priority: Minor


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: http://www.atlassian.com/software/jira