You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ee7arh <an...@2e-systems.com> on 2009/03/04 10:38:16 UTC

Error: This SpringBuilder is not being used with a SpringCamelContext and there is no applicationContext property configured

Hi,

Getting the following error when starting camel:

"This SpringBuilder is not being used with a SpringCamelContext and there is
no applicationContext property configured"

I am starting Camel from Spring by calling the camel Main class and passing
in a reference to my Spring XML file.

Within my code base I have a "SpringRouterBuilder" defined because I want to
take advantage of Spring's transactional features.

When I start camel, I want it to find my SpringRouteBuilder in my sourcebase
(in package com.mycompany.mypackage) and so I put the following XML in my
camel-server.xml:

<camel:camelContext id="camel2"
xmlns="http://activemq.apache.org/camel/schema/spring">
        <camel:package>com.mycompany.mypackage</camel:package>
</camel:camelContext>

here is my SpringRouteBuilder:

public class EventRouter extends SpringRouteBuilder {

    Policy required 
        = new SpringTransactionPolicy(bean(TransactionTemplate.class,
"PROPAGATION_REQUIRED"));

    @Override
    public void configure() throws Exception {
      
        // Routing of Main Event Queue
        from("jms:queue:incomingEventQueue")
            .policy(required)
            .to("log:incomingEventLogger?level=INFO");

    }
}

I get error stack:

[2009-03-04 10:08:30,187] org.apache.camel.util.MainSupport ERROR  - Failed:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'camel:beanPostProcessor': Cannot resolve reference to bean
'camel' while setting bean property 'camelContext'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'camel': Invocation of init method failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'com.ee.berbe.mobile.external.EventRouter': Instantiation of bean
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not instantiate
bean class [com.ee.berbe.mobile.external.EventRouter]: Constructor threw
exception; nested exception is java.lang.IllegalArgumentException: This
SpringBuilder is not being used with a SpringCamelContext and there is no
applicationContext property configured
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'camel:beanPostProcessor': Cannot resolve reference to bean
'camel' while setting bean property 'camelContext'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'camel': Invocation of init method failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'com.ee.berbe.mobile.external.EventRouter': Instantiation of bean
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not instantiate
bean class [com.ee.berbe.mobile.external.EventRouter]: Constructor threw
exception; nested exception is java.lang.IllegalArgumentException: This
SpringBuilder is not being used with a SpringCamelContext and there is no
applicationContext property configured
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	at java.security.AccessController.doPrivileged(Native Method)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
	at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)
	at
org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:606)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:366)
	at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
	at
org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:189)
	at org.apache.camel.spring.Main.doStart(Main.java:152)
	at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:47)
	at org.apache.camel.util.MainSupport.run(MainSupport.java:121)
	at org.apache.camel.util.MainSupport.run(MainSupport.java:310)
	at org.apache.camel.spring.Main.main(Main.java:72)
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'camel': Invocation of init method failed; nested
exception is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'com.ee.berbe.mobile.external.EventRouter':
Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not instantiate
bean class [com.ee.berbe.mobile.external.EventRouter]: Constructor threw
exception; nested exception is java.lang.IllegalArgumentException: This
SpringBuilder is not being used with a SpringCamelContext and there is no
applicationContext property configured
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1337)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	at java.security.AccessController.doPrivileged(Native Method)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
	at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
	... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'com.ee.berbe.mobile.external.EventRouter':
Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Could not instantiate
bean class [com.ee.berbe.mobile.external.EventRouter]: Constructor threw
exception; nested exception is java.lang.IllegalArgumentException: This
SpringBuilder is not being used with a SpringCamelContext and there is no
applicationContext property configured
	at
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	at java.security.AccessController.doPrivileged(Native Method)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:300)
	at
org.apache.camel.spring.spi.SpringInjector.newInstance(SpringInjector.java:39)
	at
org.apache.camel.spring.RouteBuilderFinder.instantiateBuilder(RouteBuilderFinder.java:121)
	at
org.apache.camel.spring.RouteBuilderFinder.appendBuilders(RouteBuilderFinder.java:85)
	at
org.apache.camel.spring.CamelContextFactoryBean.findRouteBuiders(CamelContextFactoryBean.java:526)
	at
org.apache.camel.spring.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:254)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
	... 33 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class [com.ee.berbe.mobile.external.EventRouter]:
Constructor threw exception; nested exception is
java.lang.IllegalArgumentException: This SpringBuilder is not being used
with a SpringCamelContext and there is no applicationContext property
configured
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
	at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
	at
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248)
	... 47 more
Caused by: java.lang.IllegalArgumentException: This SpringBuilder is not
being used with a SpringCamelContext and there is no applicationContext
property configured
	at
org.apache.camel.spring.SpringRouteBuilder.getApplicationContext(SpringRouteBuilder.java:89)
	at
org.apache.camel.spring.SpringRouteBuilder.bean(SpringRouteBuilder.java:50)
	at com.ee.berbe.mobile.external.EventRouter.<init>(EventRouter.java:17)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
	... 49 more


I'm using camel 1.5

Looks like I need to be creating a SpringCamelContext from my Spring XML but
have not been able to find anyway to do this. Any ideas?

Thanks
Andrew

-- 
View this message in context: http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22326547.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Re: Error: This SpringBuilder is not being used with a SpringCamelContext and there is no applicationContext property configured

Posted by "willem.jiang" <wi...@gmail.com>.
Hi , 

You can use 
SpringCamelContext.springCamelContext(applicationContext);
to create a SpringCamelContext from an applicationContext.

Willem



ee7arh wrote:
> 
> Too add a bit more information....
> 
> I found the code which throws this error in the camel source base:
> 
> public ApplicationContext getApplicationContext() {
> +        if (applicationContext == null) {
> +            CamelContext camelContext = getContext();
> +            if (camelContext instanceof SpringCamelContext) {
> +                SpringCamelContext springCamelContext =
> (SpringCamelContext) camelContext;
> +                return springCamelContext.getApplicationContext();
> +            }
> +            else {
> +                throw new IllegalArgumentException("This SpringBuilder is
> not being used
> with a SpringCamelContext and there is no applicationContext property
> configured");
> +            }
> +        }
> 
> 
> So the problem seems to be that I have an instance of CamelContext instead
> of SpringCamelContext. SpringcamelContext extends camelcontext incidently.
> 
> the questions is - how can I create an instance of SpringCamelContext from
> within my Spring xml?
> 
> To refer back to my original post, I have this piece of XML to create, I
> guess, a normal camelContext:
> 
> <camel:camelContext id="camel2"
> xmlns="http://activemq.apache.org/camel/schema/spring">
>         <camel:package>com.mycompany.mypackage</camel:package>
> </camel:camelContext> 
> 
> I was hoping it would be as simply as changing "camelContext" to
> "SpringCamelContext" but sadly not ;)
> 
> Can anyone indicate if this is something perhaps currently not supported,
> or hopefully offer a solution? maybe I can't use spring xml for this?
> 
> I am using the SpringRouteBuilder because I want to be able to ensure that
> messages are persisted from 1 queue to another (i.e. if somebody pulls out
> the plug during processing within a bean, my message will still exist on
> the "from" queue and not be lost). So if Camel supports transactions
> another way, would gladly use that instead.
> 
> Thanks for any feedback
> 
> andrew
> 

-- 
View this message in context: http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22347500.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Re: Error: This SpringBuilder is not being used with a SpringCamelContext and there is no applicationContext property configured

Posted by ee7arh <an...@2e-systems.com>.
Too add a bit more information....

I found the code which throws this error in the camel source base:

public ApplicationContext getApplicationContext() {
+        if (applicationContext == null) {
+            CamelContext camelContext = getContext();
+            if (camelContext instanceof SpringCamelContext) {
+                SpringCamelContext springCamelContext =
(SpringCamelContext) camelContext;
+                return springCamelContext.getApplicationContext();
+            }
+            else {
+                throw new IllegalArgumentException("This SpringBuilder is
not being used
with a SpringCamelContext and there is no applicationContext property
configured");
+            }
+        }


So the problem seems to be that I have an instance of CamelContext instead
of SpringCamelContext. SpringcamelContext extends camelcontext incidently.

the questions is - how can I create an instance of SpringCamelContext from
within my Spring xml?

To refer back to my original post, I have this piece of XML to create, I
guess, a normal camelContext:

<camel:camelContext id="camel2"
xmlns="http://activemq.apache.org/camel/schema/spring">
        <camel:package>com.mycompany.mypackage</camel:package>
</camel:camelContext> 

I was hoping it would be as simply as changing "camelContext" to
"SpringCamelContext" but sadly not ;)

Can anyone indicate if this is something perhaps currently not supported, or
hopefully offer a solution? maybe I can't use spring xml for this?

I am using the SpringRouteBuilder because I want to be able to ensure that
messages are persisted from 1 queue to another (i.e. if somebody pulls out
the plug during processing within a bean, my message will still exist on the
"from" queue and not be lost). So if Camel supports transactions another
way, would gladly use that instead.

Thanks for any feedback

andrew
-- 
View this message in context: http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22338004.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Re: Error: This SpringBuilder is not being used with a SpringCamelContext and there is no applicationContext property configured

Posted by ee7arh <an...@2e-systems.com>.
Hi Willem,

Thanks for quick fix, I just tested it and it works. :jumping:

Just a note for other readers, this works with the existing camelContext, no
need to declare a separate "springCamelContext"

Bregards
Andrew


<qguote author="willem.jiang">
I did a quick fix for CAMEL-1426. The patch is submitted in the trunk and
1.x-branch.

Please check out Camel 1.6.1-SNAPSHOT or 2.0-SNAPSHOT for verifaction.

Willem


willem.jiang wrote:
> 
> I see and just created a JIRA[1] to track your issue.
> It should be easy to fix :)
> 
> [1] https://issues.apache.org/activemq/browse/CAMEL-1426
> 
> Willem
> 
> ee7arh wrote:
>> The reason is that I want to use Transactions and as far as I know, only
>> Spring supports this with PROPOGATION_REQUIRED.
>> 
>> Following line does not compile in standard RouteBulder:
>> 
>> Policy required
>>         = new SpringTransactionPolicy(bean(TransactionTemplate.class,
>> "PROPAGATION_REQUIRED")); 
>> 
>> If there is a way to do transactions in basic RouteBuilder I'm all for it
>> ;)
>> 
>> Thanks
>> Andrew
>> 
>> 
>> 
>> 
>> willem.jiang wrote:
>>> Why don't you use the RouterBuilder if you are using the Spring
>>> configuration file to scan the builders?
>>>
>>> Willem
>>> andrew.hurst@2e-systems.com wrote:
>>>> Thanks,
>>>>
>>>> Any idea if this would be possible to do via XML? The problem occurs
>>>> when
>>>> Spring scans my packages during startup and finds a SpringRouteBuilder
>>>> in
>>>> there. So if I can't do this from XML it would mean that I have to put
>>>> my
>>>> SpringRouteBuilder in a package where Sprng can't scan it, then set it
>>>> up
>>>> myself somehow.... A bit unsure of how I would go about that.
>>>>
>>>> Regards
>>>> Andrew
>>>>
>>>> willem.jiang wrote:
>>>>> Hi , 
>>>>>
>>>>> You can use 
>>>>> SpringCamelContext.springCamelContext(applicationContext);
>>>>> to create a SpringCamelContext from an applicationContext.
>>>>>
>>>>> Willem
>>>>>
>>>>>
>>>>>
>>>>> Too add a bit more information....
>>>>>
>>>>> I found the code which throws this error in the camel source base:
>>>>>
>>>>> public ApplicationContext getApplicationContext() {
>>>>> +        if (applicationContext == null) {
>>>>> +            CamelContext camelContext = getContext();
>>>>> +            if (camelContext instanceof SpringCamelContext) {
>>>>> +                SpringCamelContext springCamelContext =
>>>>> (SpringCamelContext) camelContext;
>>>>> +                return springCamelContext.getApplicationContext();
>>>>> +            }
>>>>> +            else {
>>>>> +                throw new IllegalArgumentException("This
>>>>> SpringBuilder
>>>>> is
>>>>> not being used
>>>>> with a SpringCamelContext and there is no applicationContext property
>>>>> configured");
>>>>> +            }
>>>>> +        }
>>>>>
>>>>>
>>>>> So the problem seems to be that I have an instance of CamelContext
>>>>> instead
>>>>> of SpringCamelContext. SpringcamelContext extends camelcontext
>>>>> incidently.
>>>>>
>>>>> the questions is - how can I create an instance of SpringCamelContext
>>>>> from
>>>>> within my Spring xml?
>>>>>
>>>>> To refer back to my original post, I have this piece of XML to create,
>>>>> I
>>>>> guess, a normal camelContext:
>>>>>
>>>>> <camel:camelContext id="camel2"
>>>>> xmlns="http://activemq.apache.org/camel/schema/spring">
>>>>>         <camel:package>com.mycompany.mypackage</camel:package>
>>>>> </camel:camelContext> 
>>>>>
>>>>> I was hoping it would be as simply as changing "camelContext" to
>>>>> "SpringCamelContext" but sadly not ;)
>>>>>
>>>>> Can anyone indicate if this is something perhaps currently not
>>>>> supported,
>>>>> or hopefully offer a solution? maybe I can't use spring xml for this?
>>>>>
>>>>> I am using the SpringRouteBuilder because I want to be able to ensure
>>>>> that
>>>>> messages are persisted from 1 queue to another (i.e. if somebody pulls
>>>>> out
>>>>> the plug during processing within a bean, my message will still exist
>>>>> on
>>>>> the "from" queue and not be lost). So if Camel supports transactions
>>>>> another way, would gladly use that instead.
>>>>>
>>>>> Thanks for any feedback
>>>>>
>>>>> andrew
>>>>>
>>>>>
>>>>>
>>>> Quoted from: 
>>>> http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22347500.html
>>>>
>>>>
>>>
>>>
>> 
> 
> 
> 



-- 
View this message in context: http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p23314741.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Re: Error: This SpringBuilder is not being used with a SpringCamelContext and there is no applicationContext property configured

Posted by "willem.jiang" <wi...@gmail.com>.
I did a quick fix for CAMEL-1426. The patch is submitted in the trunk and
1.x-branch.

Please check out Camel 1.6.1-SNAPSHOT or 2.0-SNAPSHOT for verifaction.

Willem


willem.jiang wrote:
> 
> I see and just created a JIRA[1] to track your issue.
> It should be easy to fix :)
> 
> [1] https://issues.apache.org/activemq/browse/CAMEL-1426
> 
> Willem
> 
> ee7arh wrote:
>> The reason is that I want to use Transactions and as far as I know, only
>> Spring supports this with PROPOGATION_REQUIRED.
>> 
>> Following line does not compile in standard RouteBulder:
>> 
>> Policy required
>>         = new SpringTransactionPolicy(bean(TransactionTemplate.class,
>> "PROPAGATION_REQUIRED")); 
>> 
>> If there is a way to do transactions in basic RouteBuilder I'm all for it
>> ;)
>> 
>> Thanks
>> Andrew
>> 
>> 
>> 
>> 
>> willem.jiang wrote:
>>> Why don't you use the RouterBuilder if you are using the Spring
>>> configuration file to scan the builders?
>>>
>>> Willem
>>> andrew.hurst@2e-systems.com wrote:
>>>> Thanks,
>>>>
>>>> Any idea if this would be possible to do via XML? The problem occurs
>>>> when
>>>> Spring scans my packages during startup and finds a SpringRouteBuilder
>>>> in
>>>> there. So if I can't do this from XML it would mean that I have to put
>>>> my
>>>> SpringRouteBuilder in a package where Sprng can't scan it, then set it
>>>> up
>>>> myself somehow.... A bit unsure of how I would go about that.
>>>>
>>>> Regards
>>>> Andrew
>>>>
>>>> willem.jiang wrote:
>>>>> Hi , 
>>>>>
>>>>> You can use 
>>>>> SpringCamelContext.springCamelContext(applicationContext);
>>>>> to create a SpringCamelContext from an applicationContext.
>>>>>
>>>>> Willem
>>>>>
>>>>>
>>>>>
>>>>> Too add a bit more information....
>>>>>
>>>>> I found the code which throws this error in the camel source base:
>>>>>
>>>>> public ApplicationContext getApplicationContext() {
>>>>> +        if (applicationContext == null) {
>>>>> +            CamelContext camelContext = getContext();
>>>>> +            if (camelContext instanceof SpringCamelContext) {
>>>>> +                SpringCamelContext springCamelContext =
>>>>> (SpringCamelContext) camelContext;
>>>>> +                return springCamelContext.getApplicationContext();
>>>>> +            }
>>>>> +            else {
>>>>> +                throw new IllegalArgumentException("This
>>>>> SpringBuilder
>>>>> is
>>>>> not being used
>>>>> with a SpringCamelContext and there is no applicationContext property
>>>>> configured");
>>>>> +            }
>>>>> +        }
>>>>>
>>>>>
>>>>> So the problem seems to be that I have an instance of CamelContext
>>>>> instead
>>>>> of SpringCamelContext. SpringcamelContext extends camelcontext
>>>>> incidently.
>>>>>
>>>>> the questions is - how can I create an instance of SpringCamelContext
>>>>> from
>>>>> within my Spring xml?
>>>>>
>>>>> To refer back to my original post, I have this piece of XML to create,
>>>>> I
>>>>> guess, a normal camelContext:
>>>>>
>>>>> <camel:camelContext id="camel2"
>>>>> xmlns="http://activemq.apache.org/camel/schema/spring">
>>>>>         <camel:package>com.mycompany.mypackage</camel:package>
>>>>> </camel:camelContext> 
>>>>>
>>>>> I was hoping it would be as simply as changing "camelContext" to
>>>>> "SpringCamelContext" but sadly not ;)
>>>>>
>>>>> Can anyone indicate if this is something perhaps currently not
>>>>> supported,
>>>>> or hopefully offer a solution? maybe I can't use spring xml for this?
>>>>>
>>>>> I am using the SpringRouteBuilder because I want to be able to ensure
>>>>> that
>>>>> messages are persisted from 1 queue to another (i.e. if somebody pulls
>>>>> out
>>>>> the plug during processing within a bean, my message will still exist
>>>>> on
>>>>> the "from" queue and not be lost). So if Camel supports transactions
>>>>> another way, would gladly use that instead.
>>>>>
>>>>> Thanks for any feedback
>>>>>
>>>>> andrew
>>>>>
>>>>>
>>>>>
>>>> Quoted from: 
>>>> http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22347500.html
>>>>
>>>>
>>>
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22367210.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Re: Error: This SpringBuilder is not being used with a SpringCamelContext and there is no applicationContext property configured

Posted by Willem Jiang <wi...@gmail.com>.
I see and just created a JIRA[1] to track your issue.
It should be easy to fix :)

[1] https://issues.apache.org/activemq/browse/CAMEL-1426

Willem

ee7arh wrote:
> The reason is that I want to use Transactions and as far as I know, only
> Spring supports this with PROPOGATION_REQUIRED.
> 
> Following line does not compile in standard RouteBulder:
> 
> Policy required
>         = new SpringTransactionPolicy(bean(TransactionTemplate.class,
> "PROPAGATION_REQUIRED")); 
> 
> If there is a way to do transactions in basic RouteBuilder I'm all for it ;)
> 
> Thanks
> Andrew
> 
> 
> 
> 
> willem.jiang wrote:
>> Why don't you use the RouterBuilder if you are using the Spring
>> configuration file to scan the builders?
>>
>> Willem
>> andrew.hurst@2e-systems.com wrote:
>>> Thanks,
>>>
>>> Any idea if this would be possible to do via XML? The problem occurs when
>>> Spring scans my packages during startup and finds a SpringRouteBuilder in
>>> there. So if I can't do this from XML it would mean that I have to put my
>>> SpringRouteBuilder in a package where Sprng can't scan it, then set it up
>>> myself somehow.... A bit unsure of how I would go about that.
>>>
>>> Regards
>>> Andrew
>>>
>>> willem.jiang wrote:
>>>> Hi , 
>>>>
>>>> You can use 
>>>> SpringCamelContext.springCamelContext(applicationContext);
>>>> to create a SpringCamelContext from an applicationContext.
>>>>
>>>> Willem
>>>>
>>>>
>>>>
>>>> Too add a bit more information....
>>>>
>>>> I found the code which throws this error in the camel source base:
>>>>
>>>> public ApplicationContext getApplicationContext() {
>>>> +        if (applicationContext == null) {
>>>> +            CamelContext camelContext = getContext();
>>>> +            if (camelContext instanceof SpringCamelContext) {
>>>> +                SpringCamelContext springCamelContext =
>>>> (SpringCamelContext) camelContext;
>>>> +                return springCamelContext.getApplicationContext();
>>>> +            }
>>>> +            else {
>>>> +                throw new IllegalArgumentException("This SpringBuilder
>>>> is
>>>> not being used
>>>> with a SpringCamelContext and there is no applicationContext property
>>>> configured");
>>>> +            }
>>>> +        }
>>>>
>>>>
>>>> So the problem seems to be that I have an instance of CamelContext
>>>> instead
>>>> of SpringCamelContext. SpringcamelContext extends camelcontext
>>>> incidently.
>>>>
>>>> the questions is - how can I create an instance of SpringCamelContext
>>>> from
>>>> within my Spring xml?
>>>>
>>>> To refer back to my original post, I have this piece of XML to create, I
>>>> guess, a normal camelContext:
>>>>
>>>> <camel:camelContext id="camel2"
>>>> xmlns="http://activemq.apache.org/camel/schema/spring">
>>>>         <camel:package>com.mycompany.mypackage</camel:package>
>>>> </camel:camelContext> 
>>>>
>>>> I was hoping it would be as simply as changing "camelContext" to
>>>> "SpringCamelContext" but sadly not ;)
>>>>
>>>> Can anyone indicate if this is something perhaps currently not
>>>> supported,
>>>> or hopefully offer a solution? maybe I can't use spring xml for this?
>>>>
>>>> I am using the SpringRouteBuilder because I want to be able to ensure
>>>> that
>>>> messages are persisted from 1 queue to another (i.e. if somebody pulls
>>>> out
>>>> the plug during processing within a bean, my message will still exist on
>>>> the "from" queue and not be lost). So if Camel supports transactions
>>>> another way, would gladly use that instead.
>>>>
>>>> Thanks for any feedback
>>>>
>>>> andrew
>>>>
>>>>
>>>>
>>> Quoted from: 
>>> http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22347500.html
>>>
>>>
>>
>>
> 


Re: Error: This SpringBuilder is not being used with a SpringCamelContext and there is no applicationContext property configured

Posted by ee7arh <an...@2e-systems.com>.
The reason is that I want to use Transactions and as far as I know, only
Spring supports this with PROPOGATION_REQUIRED.

Following line does not compile in standard RouteBulder:

Policy required
        = new SpringTransactionPolicy(bean(TransactionTemplate.class,
"PROPAGATION_REQUIRED")); 

If there is a way to do transactions in basic RouteBuilder I'm all for it ;)

Thanks
Andrew




willem.jiang wrote:
> 
> Why don't you use the RouterBuilder if you are using the Spring
> configuration file to scan the builders?
> 
> Willem
> andrew.hurst@2e-systems.com wrote:
>> Thanks,
>> 
>> Any idea if this would be possible to do via XML? The problem occurs when
>> Spring scans my packages during startup and finds a SpringRouteBuilder in
>> there. So if I can't do this from XML it would mean that I have to put my
>> SpringRouteBuilder in a package where Sprng can't scan it, then set it up
>> myself somehow.... A bit unsure of how I would go about that.
>> 
>> Regards
>> Andrew
>> 
>> willem.jiang wrote:
>>> Hi , 
>>>
>>> You can use 
>>> SpringCamelContext.springCamelContext(applicationContext);
>>> to create a SpringCamelContext from an applicationContext.
>>>
>>> Willem
>>>
>>>
>>>
>>> Too add a bit more information....
>>>
>>> I found the code which throws this error in the camel source base:
>>>
>>> public ApplicationContext getApplicationContext() {
>>> +        if (applicationContext == null) {
>>> +            CamelContext camelContext = getContext();
>>> +            if (camelContext instanceof SpringCamelContext) {
>>> +                SpringCamelContext springCamelContext =
>>> (SpringCamelContext) camelContext;
>>> +                return springCamelContext.getApplicationContext();
>>> +            }
>>> +            else {
>>> +                throw new IllegalArgumentException("This SpringBuilder
>>> is
>>> not being used
>>> with a SpringCamelContext and there is no applicationContext property
>>> configured");
>>> +            }
>>> +        }
>>>
>>>
>>> So the problem seems to be that I have an instance of CamelContext
>>> instead
>>> of SpringCamelContext. SpringcamelContext extends camelcontext
>>> incidently.
>>>
>>> the questions is - how can I create an instance of SpringCamelContext
>>> from
>>> within my Spring xml?
>>>
>>> To refer back to my original post, I have this piece of XML to create, I
>>> guess, a normal camelContext:
>>>
>>> <camel:camelContext id="camel2"
>>> xmlns="http://activemq.apache.org/camel/schema/spring">
>>>         <camel:package>com.mycompany.mypackage</camel:package>
>>> </camel:camelContext> 
>>>
>>> I was hoping it would be as simply as changing "camelContext" to
>>> "SpringCamelContext" but sadly not ;)
>>>
>>> Can anyone indicate if this is something perhaps currently not
>>> supported,
>>> or hopefully offer a solution? maybe I can't use spring xml for this?
>>>
>>> I am using the SpringRouteBuilder because I want to be able to ensure
>>> that
>>> messages are persisted from 1 queue to another (i.e. if somebody pulls
>>> out
>>> the plug during processing within a bean, my message will still exist on
>>> the "from" queue and not be lost). So if Camel supports transactions
>>> another way, would gladly use that instead.
>>>
>>> Thanks for any feedback
>>>
>>> andrew
>>>
>>>
>>>
>> Quoted from: 
>> http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22347500.html
>> 
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error%3A-This-SpringBuilder-is-not-being-used-with-a-SpringCamelContext-and-there-is-no-applicationContext-property-configured-tp22326547p22347997.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.