简体   繁体   English

在Play框架2.1中集成Spring和Hibernate?

[英]Integrate Spring and Hibernate in Play framework 2.1?

I have to build an web application that integrate Spring and Hibernate in Play Framework 2.1. 我必须构建一个在Play Framework 2.1中集成Spring和Hibernate的Web应用程序。 I integrated Hibernate successfully but i don't know how to do with Spring. 我成功集成了Hibernate,但我不知道如何处理Spring。 Anynone can show me an example or way to do it. Anynone可以向我展示一个例子或方法来做到这一点。 Thanks for advanced. 谢谢你的进步。

It's very easy now in Play 2.1 with the getControllerInstance interceptor. 现在使用getControllerInstance拦截器在Play 2.1中非常容易。 Here is a sample application which has Play 2.1, Spring (with Java Config), and JPA: https://github.com/jamesward/play2bars/tree/java-spring 这是一个示例应用程序,它有Play 2.1,Spring(带Java Config)和JPA: https//github.com/jamesward/play2bars/tree/java-spring

I recommend the answer from James Ward. 我推荐James Ward的答案。 Here is some information for upgrading from a Spring Java 2.0 play app to 2.1. 以下是从Spring Java 2.0 play app升级到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/ 在2.0.4中,我使用了Spring4Play2依赖项,请参阅https://github.com/scott-phillips/Spring4Play2/blob/master/README.markdown但是在升级到2.1.1时甚至无法使用它虽然这个模块的2.1-SNAPSHOT jar在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." 我得到的错误是“插件[play.api.db.BoneCPPlugin]无法实例化。” and "java.lang.IncompatibleClassChangeError: Found interface play.api.Application, but class was expected" and googling did not bring any answer. 和“java.lang.IncompatibleClassChangeError:找到接口play.api.Application,但类是预期的”和谷歌搜索没有带来任何答案。

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", “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 你可以在这里看到我的Build.scala 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. 然后创建类似于示例的Global.java类,这就是它。

I've added this answer for people running into the same situation so that googling for the error message could bring up a solution. 我已经为遇到相同情况的人添加了这个答案,以便谷歌搜索错误消息可以提出一个解决方案。

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/ 我在Play 2中集成了spring(带有Hibernate),你可以看到一个例子(完整的工作源)和解释: http//serverbabyblog.wordpress.com/2014/03/26/activiti-on-play-2-with -spring和-休眠-JPA-示例/

Just skip all stuff, relative to "Activiti" framework. 只需跳过所有内容,相对于“Activiti”框架。

Basically, I was forced to throw out jpa and jdbc plugins of Play!. 基本上,我被迫抛出了Play的jpa和jdbc插件。 Replacing their functionality by known open-source 3-d parties. 通过已知的开源三维方取代其功能。 It's OK. 没关系。 Play JPA plugin is too narrow-scoped for my case. 播放JPA插件的范围过于狭窄。

As result transaction managed by Spring transaction manager and entire example works with spring JPA annotations(using Hibernate JPA). 作为结果事务由Spring事务管理器管理,整个示例使用spring JPA注释(使用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! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM