O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dependency injection with Spring

For this recipe, we will explore how to integrate the popular Spring Framework with a Play application. We will use Spring for bean instantiation and injection using Play controllers and service classes.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:
        activator "~run"
    
  2. Declare Spring as a project dependency in build.sbt:
        "org.springframework" % "spring-context" % "3.2.2.RELEASE",
        "org.springframework" % "spring-aop" % "3.2.2.RELEASE",
        "org.springframework" % "spring-expression" % "3.2.2.RELEASE"
  3. Create a new admin controller in foo_java/app/controllers/AdminController.java with the following code:
     package controllers; import play.*; import play.mvc.*; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required