加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

使用Spring引导游戏2.4 Java应用程序的方法是什么?

发布时间:2020-12-15 01:50:10 所属栏目:大数据 来源:网络整理
导读:https:// www.playframework.com/documentation/2.4.x/JavaDependencyInjection上的文档提到DI现在已集成到框架中: Out of the box,Play provides dependency injection support based on JSR 330. The default JSR 330 implementation that comes with Pl

https:// www.playframework.com/documentation/2.4.x/JavaDependencyInjection上的文档提到DI现在已集成到框架中:

Out of the box,Play provides dependency injection support based on
JSR 330. The default JSR 330 implementation that comes with Play is
Guice,but other JSR 330 implementations can be plugged in.

我找不到任何使用Spring的HOWTO或工作示例.

https:// www.playframework.com/documentation/2.4.x/Tutorials上的当前文档链接到示例“Play with Spring Data JPA”,网址为https:// typesafe.com/activator/template/play-spring-data -jpa但评论已经提到它已经过时了.此外,在GitHub页面https:// github.com/typesafehub/play-spring-data-jpa上有一些未解决的问题,提到它在Play 2.4.0中不起作用.

代码是2年,仍然使用Global.java类来引导Spring.我没关系,但由于方法getControllerInstance(),代码在Play 2.4中不再编译.

这个项目https:// github.com/jroper/play-spring看起来很有前景,但它在Scala中,并列出了许多TODO,以及https:// github.com/jroper/play-spring/blob/上的SpringApplicationLoader类master / core / src / main / scala / play / api / inject / spring / SpringApplicationLoader.scala看起来太复杂了我想要的只是启动一个简单的Spring上下文.

现在看起来我必须降级Play以使用旧的Global.java黑客(并找出所需的所有更改……)

(一些编辑将这些链接重新放入,它们是合法的,它不会让我……)

最佳答案
多人在Play 2.4中遇到此问题,导致其中一些人坚持使用2.3.

您从Play功能中引用的文本的问题在于它表明使用Play 2.4可以插入任何JSR 330容器,但不幸的是,它很难并且到目前为止仍然没有完全可用的解决方案.这基本上是反对戏剧自己的哲学,其中指出:

In Play 2,we wanted to make it really easy to use any data store
driver,ORM,or any other database access library without any special
integration with the web framework.
(Which is not the case when you want to use Spring ORM with Play 2.4.)

https://groups.google.com/forum/#!topic/play-framework/hFOtzSNSDsQ还讨论了此问题以及多个解决方案尝试的链接,其中最佳解决方案并未完全正常工作,但它可能适合您的需求:
https://github.com/zarinfam/play24-guice-spring

另一个解决方案是为Springs ApplicationContext创建一个单例,并在Play客户端类中使用该单例.然后(不幸的是)你没有在这些类中有依赖注入,但至少你可以以干净的依赖注入方式使用你的非Play类.

更新:
我刚刚在GitHub上创建了这个有效的Play-Java-Spring模板:https://github.com/jtdev/play-java-spring

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读