Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating from Spring framework to Play framework (Scala)

I have always used Spring framework (3.x) in my projects, using such features as:

  • security: Spring security API
  • persistence: Hibernate (auto-generate/update database scheme)
  • full text search: Hibernate Search (based on Apache Lucene)
  • IOC: Spring dependency injections

I want to migrate some of my previous projects to Play framework. Recently I've started studying Scala language along with Play framework 2.x. And I want to use the same features as before. For database I'm going to use Slick library.

Could you advise me what to use for security and full text search?

like image 780
John Mullins Avatar asked Oct 25 '13 19:10

John Mullins


People also ask

Is play better than Spring?

Play is a direct competitor to Spring framework and designed to develop and deploy web applications more efficiently and also provides better MVC framework. In terms of getting a web application up and running quickly, play is the best.

Is play framework good?

Play Framework is the best full-stack web framework available in the current market to develop Reactive Web Applications, Reactive systems, Reactive architecture, Reactive microservices, or Reactive libraries using both FP and RP paradigms, that is, FRP.

Why use play framework?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

What is play framework in Scala?

Play Framework is an open-source web application framework which follows the model–view–controller (MVC) architectural pattern. It is written in Scala and usable from other programming languages that are compiled to JVM bytecode, e.g. Java.


1 Answers

Migration to new technology is always a bumpy road, so don't expect the first thing you try to work for you - might be you need to implement something yourself. I'll get to this with a specific example in a bit.

First, Scala means scalable, not integratable. That is, if you choose to code anything in Scala, keep in mind that frameworks meant for automating things in Java mostly do not work on the Scala side. ORM is a very good example of this since Scala methods are not always exactly Java methods, so the metadata will end up in incorrect places and you'll end up having corrupt data. So the general pointer is that if you go with Scala, you really can't look into the Java ecosystem for helpers unless the helpers are completely isolated from language semantics.


Security

Assuming you took full advantage of Spring Security, you were using role-based access control. If you go with Java, you actually should be able to use Spring Security which definitely helps you with the migration and saves time writing more code. All you really need is a Spring container in your Play app and thankfully others have already solved that: Integrating Play framework 2.0 and Spring framework

On Scala side RBAC seems to be a civilized fight about semantics betwen RBAC and ACL with no clear winner. This is problematic since it seems like no one's actually working on one which means you may have to roll your own.

Persistence

With Java you should be able to use Hibernate/any JPA solution since it's not tied to a web container. Play also comes with EBeans but from what I've observed it can't be used for the most exotic use cases. Might be you'll never hit those though so it's worth trying out since it's already there.

On Scala side, as you already thought, Slick should be alright.

Full text search

Search is a really complex thing so I'd actually setup standalone Solr/ElasticSearch and integrate to its APIs instead of embed it to the app itself, no matter what language or framework is being used.

IOC

Latest Play just about supports Guice, Scala itself tries to enforce the cake pattern. Spring should be possible with the container integration linked earlier.

I hope someone else actually has good insights to comment on this because the way Play is built, especially on the Java side seems to be very IOC hostile.

like image 102
Esko Avatar answered Sep 27 '22 22:09

Esko