Nathan Jensen created CAMEL-7390:
------------------------------------

             Summary: CamelNamespaceHandler issue when using Spring's 
AbstractRefreshableApplicationContext.setAllowBeanDefinitionOverriding(false)
                 Key: CAMEL-7390
                 URL: https://issues.apache.org/jira/browse/CAMEL-7390
             Project: Camel
          Issue Type: Bug
          Components: camel-spring
    Affects Versions: 2.11.2
            Reporter: Nathan Jensen
            Priority: Minor


Some of the Spring ApplicationContext implementations (i.e. 
AbstractRefreshableApplicationContext) allow you to call 
setAllowBeanDefinitionOverriding(false) to enforce that beans initialized by 
spring do not reuse ids.  This can be especially helpful in a pluggable 
application where different developers may contribute different spring files.

CamelNamespaceHandler.registerTemplates() is helpful and automatically creates 
a template and consumerTemplate if they're not defined on a camelContext.  
Unfortunately, if there are multiple camelContexts, then it creates a template 
for each camelContext with the id of "template", which will then cause an 
exception IF the spring application context is not allowing bean definition 
overriding.  An example of the exception:

{noformat}
Caused by: 
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: Invalid bean definition with name 'template' defined in 
null: Cannot register bean definition [Generic bean: class 
[org.apache.camel.spring.CamelProducerTemplateFactoryBean]; scope=; 
abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; 
autowireCandidate=true; primary=false; factoryBeanName=null; 
factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 
'template': There is already [Generic bean: class 
[org.apache.camel.spring.CamelProducerTemplateFactoryBean]; scope=; 
abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; 
autowireCandidate=true; primary=false; factoryBeanName=null; 
factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
Offending resource: class path resource [springfile.xml]
        at 
org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:72)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:82)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.apache.camel.spring.handler.CamelNamespaceHandler.registerTemplates(CamelNamespaceHandler.java:519)
 ~[camel-spring-2.11.2.jar:2.11.2]
        at 
org.apache.camel.spring.handler.CamelNamespaceHandler$CamelContextBeanDefinitionParser.doParse(CamelNamespaceHandler.java:369)
 ~[camel-spring-2.11.2.jar:2.11.2]
        at 
org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:85)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1423)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1413)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
 ~[org.springframework.beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
 ~[org.springframework.context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
 ~[org.springframework.context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
 ~[org.springframework.context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:530)
 ~[org.springframework.context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:444)
 ~[org.springframework.context-3.1.4.RELEASE.jar:3.1.4.RELEASE]
{noformat}

This appears to only be a problem if using multiple camel contexts and setting 
allowBeanDefinitionOverriding to false.  If you need to enforce the unique bean 
ids, I suspect a workaround is to define a template with a unique id for each 
camelContext in the XML, but then you lose the helpful benefit of not having to 
define that for every context.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to