Rob
Rob

Reputation: 51

Is is possible to use Spring MVC with Groovy or Scala?

I wanted to know if it was possible to use Spring MVC with a different JVM language than Java, e.g. 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?

Upvotes: 5

Views: 2956

Answers (7)

Nathan Hughes
Nathan Hughes

Reputation: 96394

Grails is implemented with Spring baked in, Grails 3 uses Spring-Boot. So that 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.

Upvotes: 2

jeffrey
jeffrey

Reputation: 9

Your question should be classified:

  1. groovy or scala compile to class and deployed
  2. groovy not compile just deployed to tomcat
  3. using traditional spring framework with a little groovy
  4. using brand new framework to work with groovy e.g. grail

If you want using traditional spring framework e.g. spingmvc springcloud and want to add some groovy to implement business logic code, please use a new lib micro-mvc: https://github.com/jeffreyning/micro-mvc

This lib can scan interface as springbean and create a proxy to execute groovy.

Upvotes: -1

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?

Upvotes: 0

Kevin Wright
Kevin Wright

Reputation: 49705

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.

Upvotes: 0

oxbow_lakes
oxbow_lakes

Reputation: 134270

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>

Upvotes: 5

p3t0r
p3t0r

Reputation: 1980

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.

Upvotes: 3

Eric Wendelin
Eric Wendelin

Reputation: 44349

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

Upvotes: 0

Related Questions