datree
datree

Reputation: 493

Bootstrap Spring Boot in Play Framework

Any one has a sample code to bootstrap Spring Boot in a play application with Scala?

Upvotes: 4

Views: 1107

Answers (1)

Andrew Scott Evans
Andrew Scott Evans

Reputation: 1033

As for the first one, I am not sure it is really necessary to write 'special code' to mix Boot with Play. Boot is an automatic configuration and server deployment tool as part of the Spring Framework.

Scala runs on the JVM and compiles for the JVM. The resulting byte code is pretty much the same in all cases. Therefore, just write as if you were writing for java. You can even use gradle or Maven. As for a resource, this blog is a great start.

Now, for autowiring. You really just need scala beans and any necessary java conversions. Java conversions are handled implicity and just build scala features onto java objects although this is not really necessary, I believe through the enrichment/pimp my library pattern. Autowiring is just a matter of using the right annotations. The @BeanProperty annotation must be used to generate the necessary getters and setters though.

import scala.beans._
import scala.collection.JavaConversions._
import org.springframework.beans.factory.annotation.Required
import org.springframework.beans.factory.annotation.Autowired

@Component
@Autowire //if wanted
class SpringTest{
   //using javax to combine Autowire potentially differently named variables 
   @Required
   @BeanProperty 
   @Resource(name="varName")
   var resourceVar:String = null

   //using basic autowiring
   @BeanProperty
   @Autowire //same for instance variables as objects
   var autoVar:String = null


   //etc.....
}

Upvotes: 1

Related Questions