camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From EwanH <>
Subject Re: Scala and Spring config
Date Fri, 22 May 2009 11:41:31 GMT

Ok I have it sussed now...

I am using Lift as my web framework and want to incorporate camel for
routing using scala which works fine when I create my own
DefaultCamelContext and add routes manually.  But if I choose to have the
camel context bootstrapped by the standard spring  listener I could not find
a way as Lift does not use Spring.

My solution is a scala singleton that calls out to Spring to look up the
template and magically it all works 

object RouteBuilderHelper {
      lazy val context = ContextLoader.getCurrentWebApplicationContext()
      lazy val template: ProducerTemplate[Exchange] =
      def getTemplate() = template

... SomeOtherClass.scala below:

"Running camel route direct:testMe")
	      val p = RouteBuilderHelper.getTemplate

	      for (i <- 1 to 10) {
	    	p.sendBody("direct:testMe", "****Test Message #" + i);

I can see that using WebApplicationContextUtils will work as well.

Now the problem I have now is that shutdown hooks in Jetty, while seemingly
called (log message say INFO:  Shutdown hook executing) results in the
process hanging.

-- Ewan

James.Strachan wrote:
> 2009/5/22 EwanH <>:
>> My spring is a bit rusty and I am struggling to find a way to get the
>> bean
>> factory using scala inside a Lift app and yes once I get that then I can
>> get
>> the template bean as you suggest.
> I'm a tad confused too :)
> Maybe could you step back a little and describe how you're using Lift
> / Spring from an IoC perspective?
> Are you trying to get the ProducerTemplate from an object that is not
> dependency injected via Spring? e.g. from some class created by Lift?
> If so grabbing the Spring ApplicationContext (via the Spring web API)
> and then looking up the ProducerTemplate by ID is gonna be the easiest
> (adding the <template id="myId"/> element within <camelContext/> to
> export one into the spring application context)
> Otherwise, if you are trying to get the ProducerTemplate from an
> object created by Spring, just let spring inject it for you via the
> @Produces annotation.
> -- 
> James
> -------
> Open Source Integration

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message