You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Chris Pimlott (JIRA)" <ji...@apache.org> on 2015/05/27 21:46:17 UTC

[jira] [Comment Edited] (CAMEL-8801) CamelContext auto-configuration should be conditional

    [ https://issues.apache.org/jira/browse/CAMEL-8801?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14561587#comment-14561587 ] 

Chris Pimlott edited comment on CAMEL-8801 at 5/27/15 7:45 PM:
---------------------------------------------------------------

In my case, I'm using a simple FarJarRouter subclass that pulls in a Spring XML context containing a camelContext definition:

{code:java}
@SpringBootApplication
@ImportResource(value = "classpath:META-INF/spring/camelContext.xml")
public class CamelApplication extends FatJarRouter {

}
{code}

This gives an exception on startup due to there being two ``CamelContext``s defined:

{noformat}

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.apache.camel.CamelContext] is defined: expected single matching bean but found 2: camelContext,transferAndNotify
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
	at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:50)
	at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:29)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
	at org.apache.camel.spring.boot.FatJarRouter.main(FatJarRouter.java:26)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418)
	at java.lang.Thread.run(Thread.java:744)
{noformat}


was (Author: pimlottc):
I'm using a simple FarJarRouter subclass that pulls in a Spring XML context containing a camelContext definition:

{code:java}
@SpringBootApplication
@ImportResource(value = "classpath:META-INF/spring/camelContext.xml")
public class CamelApplication extends FatJarRouter {

}
{code}

This gives an exception on startup due to there being two {{CamelContext}}s defined:

{noformat}

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.apache.camel.CamelContext] is defined: expected single matching bean but found 2: camelContext,transferAndNotify
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
	at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:50)
	at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:29)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
	at org.apache.camel.spring.boot.FatJarRouter.main(FatJarRouter.java:26)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418)
	at java.lang.Thread.run(Thread.java:744)
{noformat}

> CamelContext auto-configuration should be conditional
> -----------------------------------------------------
>
>                 Key: CAMEL-8801
>                 URL: https://issues.apache.org/jira/browse/CAMEL-8801
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-spring-boot
>    Affects Versions: 2.15.2
>            Reporter: Chris Pimlott
>
> The {{@Bean}} declaration of {{CamelContext}} within {{CamelAutoConfiguration}} should be made conditional to allow the user to create it manually if they so desire.  This is useful when converting an application using an existing XML-based camelContext, for example.
> This would also make camel-spring-boot more consistent with [Spring Boot's policy of non-invasive auto-configuration|http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-replacing-auto-configuration].
> The fix is just to add a conditional annotation on the camelContext method, e.g.:
> {code}
>     @Bean
>     @ConditionalOnMissingBean(CamelContext.class)
>     CamelContext camelContext(ApplicationContext applicationContext,
>                               CamelConfigurationProperties configurationProperties) {
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)