What is the way to download a 2.4 game Java application from Spring?

The documentation at https://www.playframework.com/documentation/2.4.x/JavaDependencyInjection mentions that DI is now integrated into the structure:

The Play field provides support for dependency injection based on JSR 330. By default, the JSR 330 implementation that ships with Play, Guice, but other JSR 330 implementations can be connected.

I could not find a HOWTO or a working example that uses Spring.

Current documentation at https://www.playframework.com/documentation/2.4.x/Tutorials refers to the example “Play with Spring Data JPA” at https://typesafe.com/activator/template/play- spring -data-jpa but the comments already mention that it is out of date. In addition, on the GitHub page https://github.com/typesafehub/play-spring-data-jpa there are open problems with the mention that it does not work in Play 2.4.0.

The code is 2 years old and still uses the Global.java class to load Spring. I would be fine, but the code no longer compiles in Play 2.4 due to the getControllerInstance () method.

This https://github.com/jroper/play- spring project looks promising, but it is in Scala, and there are many TODOs listed, and the SpringApplicationLoader class is in https://github.com/jroper/play-spring/blob /master/core/src/main/scala/play/api/inject/spring/SpringApplicationLoader.scala looks too complicated when all I want to do is run a simple Spring context.

Now it seems that I need to downgrade Play to use the old Global.java hack (and find out all the necessary changes ...)

(some pls editors returned the links, they are legal, this did not allow me ...)

+6
source share
1 answer

Many people have this problem with Play 2.4, as a result of which some of them stick to 2.3.

The problem with the text that you specified in the Play functions is that it assumes that you can connect any JSR 330 container with Play 2.4, but, unfortunately, it is very difficult to this day, it still does not exist completely working solutions. This is mainly against the idea of ​​their own philosophy, which states:

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

https://groups.google.com/forum/#!topic/play-framework/hFOtzSNSDsQ this issue is also discussed with links to several solution attempts, of which the best solution does not fully work, but it can satisfy your needs: https: / /github.com/zarinfam/play24-guice-spring

Another solution would be to create a singleton for the Springs ApplicationContext and use that singleton in your client game classes. Then (unfortunately) you do not have dependency injection in these classes, but at least you can use your non-Play classes in pure injection mode.

Updated: I just created this working Play-Java-Spring template on GitHub: https://github.com/jtdev/play-java-spring

+6
source

All Articles