[Play 2.4] Spring Dependency Injection

872 views
Skip to first unread message

Prag

unread,
Jul 17, 2015, 11:49:01 AM7/17/15
to play-fr...@googlegroups.com
In Play < 2.4, Spring could relatively easily be used using GlobalSettings.getControllerInstance(), but in 2.4 it is very hard to get it working.

I have seen multiple people/post trying to get it working, but none of the code examples seem to work:

Is there solution for this?


sachin walia

unread,
Jul 17, 2015, 1:26:02 PM7/17/15
to play-fr...@googlegroups.com
Try James Ward's fork:


Seems like he is trying to make it compatible with 2.4.x

thanks.

Archie Sheran

unread,
Jul 17, 2015, 5:21:32 PM7/17/15
to play-fr...@googlegroups.com
Here is a working project https://github.com/zarinfam/play24-guice-spring I used his approach, removed the annotations and set the ApplicationContext to be static so that I can close it inside a lifecycle shutdown hook, otherwise you will be creating a new applicationcontext each time you reload the project. I intend to refactor the code and use the extension from guice whenever I can take a break from developing new features. The extension is here https://google.github.io/guice/api-docs/4.0/javadoc/com/google/inject/spring/SpringIntegration.html 

Prag

unread,
Jul 18, 2015, 2:24:15 PM7/18/15
to play-fr...@googlegroups.com
Unfortunately that fork is still work in progress: https://github.com/jamesward/play-spring/issues/1

Prag

unread,
Jul 18, 2015, 2:29:26 PM7/18/15
to play-fr...@googlegroups.com
I tried zarinfam/play24-guice-spring before, couldn't get it working, but now it does seem to work.
Updated this one (Play 2.4, Scala, Spring Data JPA): https://github.com/jtdev/play-scala-spring-data-jpa

Edgar Eler

unread,
Aug 3, 2015, 4:17:30 PM8/3/15
to play-framework
Prag, do you want to remove the Global.java file, as recommended by Play docs (https://www.playframework.com/documentation/2.4.x/GlobalSettings)?

I'm asking you this because I'm using Spring Data JPA and I tried to update my code to 2.4.2 by removing the GlobalSettings (and Global.java) but I got several "ProvisionException: Unable to provision..." errors and I was forced to remain in 2.3.9.

Is your source at Github working with Global.java? Will you try to remove GlobalSettings?

Thank you for the advance.

--
Edgar Eler
edgar.systems

Ricardo Sansores

unread,
Aug 4, 2015, 1:49:39 AM8/4/15
to play-framework
I wasn't able to make it work. I will have to stick in play 2.3 for sometime. I was trying to migrate mainly because I was having leaks with boneCP but I found a plugin for hikary that works in play 2.3. http://edulify.github.io/play-hikaricp.edulify.com/

I hope that play developers try to make easier the intergration with other DI frameworks, wiring so strongly to one or another library can be a dealbreaker. 

Prag

unread,
Aug 12, 2015, 2:07:51 PM8/12/15
to play-framework
I have just removed Global.java (from https://github.com/jtdev/play-scala-spring-data-jpa ) , it wasn't used, so it was obsolete.
There also was an error is my previous commit, during testing, I had one SBT config file set to an old Play version, but it is fixed now.

Although I couldn't get Springs @Transactional or JEE versions of those to work yet on Play controllers, some other annotations did work.

Prag

unread,
Aug 20, 2015, 8:21:10 PM8/20/15
to play-framework
Here another solution, thanks to Springs Spring-Guice integration project:

It's similar to https://github.com/zarinfam/play24-guice-spring , but the former is cleaner imo (and thus a bit easier), because 1) Spring-Guice is simply referenced via Maven instead of having the code copied into your own project and 2) it's uses Spring-Guice from a client perspective using the SpringModule class, instead of having Spring-Guice modified to call your own Spring config.
Reply all
Reply to author
Forward
0 new messages