You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bocamel <jo...@gmail.com> on 2015/05/05 14:59:53 UTC

@BeanInject ignored in Groovy when called as a script

Because groovy script called by Camel cannot be debugged under IDE, I created
my script as a hybrid so I can easily switch it between the bean mode and
script mode:
//==================
class GroovyProc4 {
	@BeanInject('myConfig')
	MyConfig myConfig
	
	public void process(Exchange exchange) {
		println(myConfig?.name)
	}
}

def GroovyProc4 mybean = new GroovyProc4()
//mybean.myConfig = MyConfig.getInstanceFromRegistry(exchange.context,
"myConfig")
mybean.process(exchange)
//==================

In the following route, I can choose to run the above processor as a script
or bean.
    <camel:route autoStartup="true">
        <camel:from uri="timer://test?period=10s"/>
         <camel:to uri="bean:groovyProc4" />
        
    </camel:route>

But when I ran it as a script, the @BeanInject in the class was ignored and
I would have to explicitly initialize the member property myConfig by
retrieving the value from Registry (in the commented out statement in the
script above).  Is this the expected behavior?   Thanks for any help!




--
View this message in context: http://camel.465427.n5.nabble.com/BeanInject-ignored-in-Groovy-when-called-as-a-script-tp5766708.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: @BeanInject ignored in Groovy when called as a script

Posted by bocamel <jo...@gmail.com>.
Claus,

What you suggested worked beautifully, as always!

Thank you all very much for being so helpful.





--
View this message in context: http://camel.465427.n5.nabble.com/BeanInject-ignored-in-Groovy-when-called-as-a-script-tp5766708p5766783.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: @BeanInject ignored in Groovy when called as a script

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Its likely because he creates the instance himself using the new
constructor. That does not do any IoC

def GroovyProc4 mybean = new GroovyProc4()

You would need to do the IoC yourself or let Camel create it using its injector

def GroovyProc4 mybean =
camelContext.getInjector().newInstance(GroovyProc4.class);



On Tue, May 5, 2015 at 4:34 PM, Henryk Konsek <he...@gmail.com> wrote:
> Hi,
>
> This is Spring? Can you send us the Maven example reproducing the issue?
>
> Cheers!
>
> wt., 5.05.2015 o 15:01 użytkownik bocamel <jo...@gmail.com> napisał:
>
>> Because groovy script called by Camel cannot be debugged under IDE, I
>> created
>> my script as a hybrid so I can easily switch it between the bean mode and
>> script mode:
>> //==================
>> class GroovyProc4 {
>>         @BeanInject('myConfig')
>>         MyConfig myConfig
>>
>>         public void process(Exchange exchange) {
>>                 println(myConfig?.name)
>>         }
>> }
>>
>> def GroovyProc4 mybean = new GroovyProc4()
>> //mybean.myConfig = MyConfig.getInstanceFromRegistry(exchange.context,
>> "myConfig")
>> mybean.process(exchange)
>> //==================
>>
>> In the following route, I can choose to run the above processor as a script
>> or bean.
>>     <camel:route autoStartup="true">
>>         <camel:from uri="timer://test?period=10s"/>
>>          <camel:to uri="bean:groovyProc4" />
>>
>>     </camel:route>
>>
>> But when I ran it as a script, the @BeanInject in the class was ignored and
>> I would have to explicitly initialize the member property myConfig by
>> retrieving the value from Registry (in the commented out statement in the
>> script above).  Is this the expected behavior?   Thanks for any help!
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/BeanInject-ignored-in-Groovy-when-called-as-a-script-tp5766708.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: @BeanInject ignored in Groovy when called as a script

Posted by Henryk Konsek <he...@gmail.com>.
Hi,

This is Spring? Can you send us the Maven example reproducing the issue?

Cheers!

wt., 5.05.2015 o 15:01 użytkownik bocamel <jo...@gmail.com> napisał:

> Because groovy script called by Camel cannot be debugged under IDE, I
> created
> my script as a hybrid so I can easily switch it between the bean mode and
> script mode:
> //==================
> class GroovyProc4 {
>         @BeanInject('myConfig')
>         MyConfig myConfig
>
>         public void process(Exchange exchange) {
>                 println(myConfig?.name)
>         }
> }
>
> def GroovyProc4 mybean = new GroovyProc4()
> //mybean.myConfig = MyConfig.getInstanceFromRegistry(exchange.context,
> "myConfig")
> mybean.process(exchange)
> //==================
>
> In the following route, I can choose to run the above processor as a script
> or bean.
>     <camel:route autoStartup="true">
>         <camel:from uri="timer://test?period=10s"/>
>          <camel:to uri="bean:groovyProc4" />
>
>     </camel:route>
>
> But when I ran it as a script, the @BeanInject in the class was ignored and
> I would have to explicitly initialize the member property myConfig by
> retrieving the value from Registry (in the commented out statement in the
> script above).  Is this the expected behavior?   Thanks for any help!
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/BeanInject-ignored-in-Groovy-when-called-as-a-script-tp5766708.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>