Monday, June 18, 2007

Spring + JRuby on Rails

I've only been threatening to do this for a year, but I finally added the necessary stuff to have JRuby on Rails talking to Spring. There's a lot more to come here, but this controller code demonstrates being able to get ahold of a Spring WebApplicationContext in a Ruby on Rails controller.

class TestservletController < ApplicationController
include Java
import javax.servlet.ServletContext
import org.springframework.web.context.WebApplicationContext
import org.springframework.web.context.support.WebApplicationContextUtils

def showcontext
app_context = WebApplicationContextUtils.getWebApplicationContext($servlet_context)
render_text app_context.display_name
end
end


In order for this to work, you'll have to use the very latest goldspike-snapshot plugin from SVN trunk. I just checked in the code to expose $servlet_context earlier today. Obviously this code will only work using a servlet container, and you'll need to have Spring and necessary deps in WEB-INF/lib and have the Spring context loader listener in your web.xml. From here, my next step is some metaprogramming to allow you to add spring bean accessors into your controllers.

9 comments:

Unknown said...

jruby/ruby newbie here.. i'm guessing the usual command for getting goldspike is not going to pull your patch correct?

script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike

if not, could you let me know the correct command?

thanks!

Unknown said...

that should be

script/plugin install svn://rubyforge.org/var/svn
... /jruby-extras/trunk
... /rails-integration/plugins
... /goldspike

Ryan Platte said...

Tyler Jennings got this running outside a servlet container:

Spring IOC in JRuby - life outside the container

Knox Karter said...

Great information on your site here. I love this post because we can get some useful information from your blog. I expect more post from you guys.

Advertising Logo

Unknown said...

You'll be able to possibly acquire vid step additionallyDiablo 3 Items and also have the initially mention of the springtime coffee bean technique change on its own so that it does not have to experience application_context.get_bean() each time. Undecided GW2 Goldit'd create a big difference, but it is a choice.

Unknown said...

Love this! Sure makes biking
android phone cheap look fun! :)

Unknown said...

Since I have studied this poems, I knowed best cheap android phones that wirting a great poems is difficult. Also I think the techology is so important~

Unknown said...

Sometimes I get so sick of the way women present themselves online, and flatter their way into relationships with perfect strangers on social media in order to increase their own popularity, that I want to puke. I envision writing a whole post on the subject someday, but since that’s probably not gonna happen cause I’m

www.wv-medical-negligence-lawyer.com |

automotive-law |

http://www.butgem-programcilik-egitimi.com |

www.customsoftwaremasters.com |

findabusinessaddress.com |

im16 |

http://www.moleculareconomics.com |

www.qrgl-technology.org |

subito2.co.uk |

yonsetravel |

Unknown said...

Hi. You have given such an interesting account of the events. The reaction would have certainly proved some of the communities. But personally I feel that you made the right decision. You just need to give it some time to settle down
resourcesworkforce.com |

http://www.camorhino.com |

studentsfirstmi.com |

http://www.apron2apronsisters.com |

adamoagency.com |