camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From EwanH <drldgt...@sneakemail.com>
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] =
context.getBean("myTemplate").asInstanceOf[ProducerTemplate[Exchange]]
  
      def getTemplate() = template
}

... SomeOtherClass.scala below:

          Log.info("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 <drldgtq02@sneakemail.com>:
>> 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)
> http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/context/support/WebApplicationContextUtils.html#getWebApplicationContext(javax.servlet.ServletContext)
> 
> 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
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://fusesource.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Scala-and-Spring-config-tp23667388p23668835.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message