Reputation: 99
I have to build an web application that integrate Spring and Hibernate in Play Framework 2.1. I integrated Hibernate successfully, but how can I do it with Spring?
Upvotes: 5
Views: 4837
Reputation: 1907
I integrated spring (with Hibernate) within Play 2, you can see an example (full working source) and explanation here: http://serverbabyblog.wordpress.com/2014/03/26/activiti-on-play-2-with-spring-and-hibernate-jpa-example/
Just skip all stuff, relative to "Activiti" framework.
Basically, I was forced to throw out jpa and jdbc plugins of Play!. Replacing their functionality by known open-source 3-d parties. It's OK. Play JPA plugin is too narrow-scoped for my case.
As result transaction managed by Spring transaction manager and entire example works with spring JPA annotations(using Hibernate JPA). It is really cross-platform example, because you can take all the spring stuff and move from play to other framework.
Good luck!
Upvotes: 0
Reputation: 1764
I recommend the answer from James Ward. Here is some information for upgrading from a Spring Java 2.0 play app to 2.1.
In 2.0.4 I've used the Spring4Play2 dependency, see https://github.com/scott-phillips/Spring4Play2/blob/master/README.markdown but I could not get this to work when upgrading to play 2.1.1 even though there is a 2.1-SNAPSHOT jar of this module at https://maven.library.tamu.edu/content/repositories/snapshots/play/spring_2.9.1/2.1-SNAPSHOT/
The error I got was "Plugin [play.api.db.BoneCPPlugin] cannot been instantiated." and "java.lang.IncompatibleClassChangeError: Found interface play.api.Application, but class was expected" and googling did not bring any answer.
So I went ahead and looked at the nice example from James Ward, dropped that plugin, and just added
"org.springframework" % "spring-context" % "3.2.1.RELEASE",
to my Build.scala as you can see here https://github.com/jamesward/play2bars/blob/java-spring/project/Build.scala
then created the Global.java class similar to the example, and that was about it.
I've added this answer for people running into the same situation so that googling for the error message could bring up a solution.
Upvotes: 0
Reputation: 29433
It's very easy now in Play 2.1 with the getControllerInstance
interceptor. Here is a sample application which has Play 2.1, Spring (with Java Config), and JPA:
https://github.com/jamesward/play2bars/tree/java-spring
Upvotes: 8