5

我必须在 Play Framework 2.1 中构建一个集成 Spring 和 Hibernate 的 Web 应用程序。我成功集成了 Hibernate,但是如何使用 Spring 来实现呢?

4

3 回答 3

8

现在在 Play 2.1 中使用getControllerInstance拦截器非常容易。这是一个具有 Play 2.1、Spring(带有 Java Config)和 JPA 的示例应用程序: https ://github.com/jamesward/play2bars/tree/java-spring

于 2013-04-04T12:34:43.563 回答
0

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!

于 2014-04-06T08:40:40.457 回答
0

我推荐詹姆斯沃德的答案。以下是从 Spring Java 2.0 play 应用程序升级到 2.1 的一些信息。

在 2.0.4 中,我使用了 Spring4Play2 依赖项,请参阅https://github.com/scott-phillips/Spring4Play2/blob/master/README.markdown但即使在升级到玩 2.1.1 时我也无法使用它虽然在https://maven.library.tamu.edu/content/repositories/snapshots/play/spring_2.9.1/2.1-SNAPSHOT/有这个模块的 2.1-SNAPSHOT jar

我得到的错误是“无法实例化插件 [play.api.db.BoneCPPlugin]。” 和“java.lang.IncompatibleClassChangeError: Found interface play.api.Application, but class is expected”和谷歌搜索没有带来任何答案。

所以我继续看詹姆斯沃德的好例子,放弃了那个插件,然后添加了

“org.springframework”%“spring-context”%“3.2.1.RELEASE”,

到我的 Build.scala,你可以在这里看到https://github.com/jamesward/play2bars/blob/java-spring/project/Build.scala

然后创建类似于示例的 Global.java 类,仅此而已。

我已经为遇到相同情况的人添加了这个答案,以便谷歌搜索错误消息可以找到解决方案。

于 2013-04-19T14:36:37.340 回答