Using Spring as a dependency injection framework with play 2.4.x?

后端 未结 3 1105
执念已碎
执念已碎 2021-02-08 23:22

I am exploring play-scala 2.4.2 and trying to get the spring DI working with it. I see there are a lot of changes in play 2.4.x and old way of overriding the GlobalSettings.getC

3条回答
  •  走了就别回头了
    2021-02-08 23:54

    Just in case it can help someone, I also worked on a solution that is working based off of jroper's project: https://github.com/jroper/play-spring. The key was to use spring's scanning feature to "load" the Play classes:

    ctx.scan(packages:_*)

    with the default play's packages:

    def defaultPackages(): Seq[String] = Seq("router", "play", "controllers")

    The solution works with 1 hack: you need to add the @javax.inject.Named next to the @Singleton annotations in the Play classes so that Spring can scan them and load them (i.e you need to "fork" the Play version you are using, but it's a rather small and easy change). So here is my sample app with the SpringApplicationLoader: https://github.com/remithieblin/play24_spring

提交回复
热议问题