You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Claus Ibsen (JIRA)" <ji...@apache.org> on 2009/09/20 10:13:52 UTC

[jira] Resolved: (CAMEL-2027) NullPointerException when defining Camel route using Spring JavaConfig

     [ https://issues.apache.org/activemq/browse/CAMEL-2027?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen resolved CAMEL-2027.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.1.0

trunk: 816992.

> NullPointerException when defining Camel route using Spring JavaConfig
> ----------------------------------------------------------------------
>
>                 Key: CAMEL-2027
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2027
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-spring
>    Affects Versions: 2.0.0
>            Reporter: Dragisa Krsmanovic
>            Assignee: Claus Ibsen
>             Fix For: 2.1.0
>
>
> Following unit test fails. 
> Similar test, but using Spring XML with <routeBuilder ref="..."/> instead of Spring JavaConfig,  would succeed.
> {code}
> @ContextConfiguration(
>     locations = "org.plos.camel.BeanJavaConfigTest$ContextConfig",
>     loader = JavaConfigContextLoader.class
> )
> public class BeanJavaConfigTest extends AbstractTestNGSpringContextTests {
>   @EndpointInject(uri = "mock:end")
>   protected MockEndpoint endpoint;
>   @EndpointInject(uri = "mock:error")
>   protected MockEndpoint errorEndpoint;
>   @Produce(uri = "direct:start")
>   protected ProducerTemplate producer;
>   @Test
>   @DirtiesContext
>   public void testSomething() throws Exception {
>     endpoint.expectedMessageCount(1);
>     endpoint.message(0).body().isEqualTo("Message Body");
>     producer.sendBody("Message Body");
>     endpoint.assertIsSatisfied();
>   }
>   public static class SomeBean {
>     @Handler
>     public String someMethod(String body) {
>       System.out.println("Received: " + body);
>       return body;
>     }
>   }
>   @Configuration
>   public static class ContextConfig extends SingleRouteCamelConfiguration {
>     @Bean
>     @Override
>     public RouteBuilder route() {
>       return new RouteBuilder() {
>         @Override
>         public void configure() throws Exception {
>           from("direct:start")
>               .bean(new SomeBean())
>               .to("mock:end")
>               .errorHandler(deadLetterChannel("mock:end"));
>         }
>       };
>     }
>   }
> }
> {code}
> Error stack:
> {noformat}
> java.lang.IllegalStateException: Failed to load ApplicationContext
> ...
> Caused by: java.lang.NullPointerException
> 	at org.apache.camel.spring.spi.ApplicationContextRegistry.lookup(ApplicationContextRegistry.java:41)
> 	at org.apache.camel.component.bean.BeanInfo.createParameterMappingStrategy(BeanInfo.java:115)
> 	at org.apache.camel.component.bean.BeanProcessor.<init>(BeanProcessor.java:55)
> 	at org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:156)
> 	at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:276)
> 	at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:116)
> 	at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:439)
> 	at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:126)
> 	at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:569)
> 	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:924)
> 	at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:901)
> 	at org.apache.camel.spring.SpringCamelContext.maybeDoStart(SpringCamelContext.java:165)
> 	at org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:160)
> 	at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:52)
> 	at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:816)
> 	at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:99)
> 	at org.apache.camel.spring.SpringCamelContext.afterPropertiesSet(SpringCamelContext.java:87)
> 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
> 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
> 	... 74 more
> {noformat}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.