Wednesday, December 3, 2008

Rod Johnson: "Can Ruby on Rails do that?"

Adrian Coyler presented tonight's keynote at SpringOne.  Once again Grails was a large part of the presentation.  During the demo, he created a grails app from scratch.  Nothing new, we've seen it all before.  Easily creating a web application with minimal code.  However, the more impressive piece of the presentation was when Adrian integrated the application with an existing Spring Integration application.  

It was done with great ease.  Adrian performed the following simple steps to successfully integrate the existing application:
  • Copied all the spring integration jars into the grails-app/lib directory.
  • Copied the existing application's spring config file into the grails-app/resources/spring directory.
  • Added a "cafe" property to his Grails service in order to inject the existing application's spring bean.
  • Invoked the Cafe interface from the Grails service method.
That was it.  To which Rod Johnson commented from the crowd "Can Ruby on Rails do that?"  

I'd like to hear from the JRuby and Rails communities.  I have to believe there's a way to call an existing spring application bean via a Ruby on Rails app using JRuby.  Even if it requires some custom code.

Is it possible?  If it isn't simple, are there plans to provide tighter integration to allow organizations to re-use existing spring beans in Rails projects?


Bob McWhirter said...

We're working on all of that over here at the JBoss Odd Thesis.

You'll be able to get ahold of anything you need from the Java side of the world, and definitely be able to inject stuff or grab the bean-factory you want.

And Since JBoss supports Spring stuff...

Graeme Rocher said...


Good to hear plans are afoot to provide features that have been available in Grails for years.

Of course all of this will tie you to the JBoss runtime and environment. Why would you want to do this with Jboss on Rails when you can use Grails and maintain portability? ;-)

Mark Thomas said...

Yes, Ruby on Rails can do that. Here's a presentation on JRoR, and starting around slide 32 it talks about accessing Spring beans from RoR. Last slide has more links.

Flexpert said...

Seriously... not to join in on a pathetic flame war, but what are the roots of Grails? Groovy + Rails? Glad to hear of the awesome innovation coming from your camp.

Graeme Rocher said...

One thing is accessing Spring beans, which the example you gave is using the look-up mechanics rather than supporting autowiring like Grails does. Another thing is implementing code that works with the Spring framework.

Since JRuby lacks support for annotations, generics and a byte code format that supports static signatures this is not possible and severly limits any integration efforts.

Yeah we've heard that one before and thanks to the Rails community for some of the inspiritation they provided in the early days. RoR really brought some great ideas to the table.

Having said that innovation moves on, Grails supports conversational state management, declarative transactions, tag libraries and many features missing out of the box in RoR. Those who try to label it as a clone are missing out unfortunately.

Noel said...

"Of course all of this will tie you to the JBoss runtime and environment"....

pot calling kettle black by any chance.....

Javatechnologist said...

A better question would be why would I use Spring if I was using Ruby. Of course you can call a java class from a ruby script, but I think the real question is what is under the covers of all the calls that are left in the call stack using Groovy with Grails.

Javatechnologist said...

To clarify, why would I bother with Spring even if I were using JRuby. I am a spring expert and in the camp of people that is a ruby convert, so spare me the Spring overviews, thx.

Tyler Jennings said...
This comment has been removed by the author.
Tyler Jennings said...

Yeah, RoR can do that. We've been running rails as the rendering engine for an legacy Java application that runs Spring IOC.

We may end up keeping parts of the application in a hybrid state, but most likely it will end up becoming a pure Rails stack.

Our "hybrid" application has been in production for about a year. There is a rails plugin for Spring IOC:

mugwump64 said...

Phew, I think Spring has come a long way from making j2ee simpler to being a huge complex, bloated behemoth itself. After shifting around tons of configuration-files, spilling these strange syntactic beasts that annotations are all over your code, you come to realize that this is a gigantic hack to work around the fact that both java and groovy are missing important language features to make your code readable.

So, maybe instead of yelling "the Railies don't have Annotations!!!", take a look into language features like opening up classes, eval, blocks etc. Rails/Ruby does not have annotations because there is no need to have them, The beauty and the simplicity of RoR comes from the fact that you do not need several different (xml, annotations, code, aspects...) to write your app, but you can stay in ruby all the time. Huge reduction of complexity. So instead of complaining about missing idiom-x or idiom-y, try to think for a while, why you needed the idiom in the first place - and that it only solves a problem in java that you do not really have in ruby.

Vita Rara said...

The short answer is yes Ruby on Rails can do that when running under JRuby. (I use this ability everyday in my work.)

It's nice that Grails can do it, although I would be more surprised if it couldn't do it. It's really not a big deal. After all Grails IS built on top of Spring.

Wrapping Java services in a Ruby facade is very easy. My experience in the Java to Ruby transition is that things that seem like a big deal in Java are trivial in [J]Ruby. So, much so that no one bothers to waste time doing posts about it. (For instance I did my Spring integration in about 5-10 minutes from conception to working.)

Mark Menard