Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 419
Rob Avatar asked Dec 23 '09 16:12

Rob


People also ask

Can I use Scala with Spring?

In conclusion, Scala can be considered a first class citizen for a Spring-boot based application and there is no special configuration required to get a Scala based Spring-boot application to work. It just works!

Is Spring MVC still used?

Yes. Whenever someone uses Spring Boot for creating RESTful web services, chances are they are using Spring MVC (part of Spring Web starter, see http://start.spring.io and search Web in dependencies) although Spring has also been offering another web framework, Spring WebFlux.

Can we use spring boot and Spring MVC together?

Yes, you can use Spring MVC with Spring Boot. To create and run a Spring MVC web application in spring boot, you need to add the spring-boot-starter dependency in your pom. xml file.

Is Spring Boot and Spring MVC same?

Spring Boot is considered a module of the Spring framework for packaging the Spring-based application with sensible defaults. Spring MVC is considered to be the model view controller-based web framework under the Spring framework. For building a Spring-powered framework, default configurations are provided by it.


3 Answers

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>
like image 174
oxbow_lakes Avatar answered Oct 01 '22 09:10

oxbow_lakes


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.

like image 28
p3t0r Avatar answered Oct 03 '22 09:10

p3t0r


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.

like image 31
Nathan Hughes Avatar answered Oct 02 '22 09:10

Nathan Hughes