views:

422

answers:

6

I wanted to know if it was possible to use Spring MVC with a dynamic language like Groovy or Scala. Or can Groovy only be run on Grails?

Also if it is possible, is this something which people try often, or do they just stick to the framework traditionally used?

+2  A: 

Grails is implemented on top of Spring MVC, so it is definitely possible. You could also use Scala with Spring MVC. I don't know that you'd get the most mileage out of Scala with Spring MVC -- not a lot of opportunities to use Scala's functional programming features -- but there's nothing stopping you from trying it out.

Nathan Hughes
A: 

I cannot speak for Scala, but I have personally used Spring with Groovy. Match made in heaven :)

Eric Wendelin
+2  A: 

Sure, spring has excellent support for dynamic languages like Groovy. There is an entire chapter in the reference manual: http://static.springsource.org/spring/docs/2.5.6/reference/dynamic-language.html

As for scala; I tried doing this and it is possible. The problem is that JSP (or for that matter most templating languages supported by spring mvc) doesn't 'understand' scala collection types so I found myself converting between scala and java collections quite a lot. This should be better in Scala 2.8.0 but I haven't tested this myself.

p3t0r
+1  A: 

Spring works perfectly well with scala because scala compiles to normal .class files which are Java-equivalent bytecode. I use Spring and scala all the time. It's even possible to use the Spring XML-extensibility to add support for scala-specific types, for example:

<bean class="my.scala.Class">
    <property name="listProp">
        <scala:list value-type="java.lang.Integer">
            <value>1</value>
        </scala:list>
    </property>
</bean>
oxbow_lakes
A: 

Spring works very well with Scala, although Scala itself has features that mean you don't need a dependency injection framework (such as Spring) in many cases.

Also, Scala isn't a dynamic language, it's a static language just as Java is. One of the primary goals of Scala was maximum interoperability with Java. This means that Scala compiles down to class files that look and feel just like Java objects, and can be seamlessly used as Java objects by external libraries and frameworks, such as Spring.

Kevin Wright
A: 

Well, what about writing the business logic in scala, so that the functional way scales well in multic core environments and let the rest handled by Spring and Hibernate. I think this is a pretty nice way to get the best of both worlds. Of course one can usw lift as a web app framework, but i think Spring is more actually mature and has more features. But the business logic is where the ball is rolling and so Scala and FP can handle this better than imperative java.

Right?

Harald Rätscher