Integrating Play framework 2.0 and Spring framework - java

I have developed a Spring/JPA application: the service, repository and domain layers are nearing completion.
The only layer that is missing is the web layer. I am considering using Playframework 2.0 for the web layer but I am not sure whether I can inject/use spring beans in my Playframework 2.0 classes.
Is this possible? If so how?

You can. Updated for Play 2.5.x:
https://github.com/remithieblin/play-spring-loader

Alex.p is right there is support for spring in PlayFramework
Have a look here :
http://typesafe.com/blog/announcing-play-framework-21-the-high-velocit
and on example here :
https://github.com/guillaumebort/play20-spring-demo
Cheers
I just tested it on my project it works but on playframework 2.1 in 2.0 it didn't work.

Here is a another way of injecting beans using Spring. Standard annotations are used. No plugin is required.
https://github.com/huntc/play-spring

There's already support for the Spring IoC container in Play. It's just a matter of editing the application.conf file as mentioned in the linked to article.
Ignore the above see comment: it seems that this was dropped in playframework 2.0.

Related

How to use swagger without annotations

I am working on a java project which does not use spring boot. I am asked to integrate swagger into my project. I have been searching the internet on how to do it without spring boot, but I have found no clue.
Manual is the way to go. Luckily, they have a tool! https://swagger.io/tools/swagger-editor/ The other great thing is that Swagger is not Java specific so it can be re-used for other REST implementations in other languages.
Spring Boot is just an integration for Swagger. You can also make use of Swagger withtout using Spring Boot.
You can use Swagger core library for getting Swagger to work.
https://github.com/swagger-api/swagger-core

Is there any annotation based version for spring web flow?

I have been working on an infrastructure project that has a myriad of pages that used in numerous flow based scenarios. I eager to use a standard framework for facilitating this flows. I have a glance on spring web flow and I realize it is difficult to deal with all of the XML stuff like flow files. Could you please tell me is there an annotation base version instead of these XML files? Or Is there any other frameworks that use annotation based approach for this purpose. Moreover, I saw Seam framework, but like Spring Web Flow it has an XML based feature. Additionally, I read some articles about Netui Page Flows. Even though it has annotation based flows, as you know it is a very old framework and discontinued now.
I use this links:
spring web flow support in intellij idea 12
Spring Web Flow Ref Book
spring web flow
As I need this xml based file for create a web flow for my JSP pages into my enterprise application, after month looking for best solutions and frameworks, finally I find Spring Statemachine for my porpuse. I put that here for someone in future that looks for object-oreinted state machine that can be used in her/his page flow.
Thank you Spring :)

How to migrate spring annotation-based Hibernate code to Java EE

First of all: here is my code: https://github.com/s1ddok/todosapp
I'm learning java technologies. I forked a demo project on github and for now my goal is to add login (user specific todos) and hibernate mysql stuff. I successfully done it for -spring version. Now I want to do the same stuff for java ee.
How do I migrate annotation based hibernate code (Entities and config) to java ee? Is it possible to simply reuse them? I heard that you have to use xml config with Java EE, is it true?
My requirement is to use same front-end (backbone) and same database for both -spring and -javaee. This is my goal. I have to implement same-functionality REST service with spring and javaee.
I'm completely stuck with that.
With JavaEE you do not have to use much XML configs (in comparison with the old J2EE), but you can do most things with annotations.
Regarding database access you can still use Hibernate (JPA), since JPA is part of the JavaEE spec. The Json annotations like com.fasterxml.jackson.annotation.JsonIdentityInfo are not part of JavaEE spec (yet), so you might have to use JAXB instead.
Regarding REST you want to have a look at JAX-RS. The annotations are different in comparison to Spring (#ApplicationPath, #Path, #GET, ...), but you should be able to achieve the same result for you application.
For security (login) you have to look at application server specific options, since this be will standarized only in JavaEE 8 (JSR 375).

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. I integrated Hibernate successfully, but how can I do it with Spring?
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
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.
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!

Integrating JackSon for JSON View with Spring 2.5

We are using Spring 2.5 and spring-json for JSON support. We have the below configuration in views.xml
<bean name="jsonView" class="org.springframework.web.servlet.view.json.JsonView"/>
Now, we have learnt that Spring 3.x uses JackSon API internally for JSON support. My question is how can we override the default implementation of Spring 2.5 to use JackSon - The way Spring 3.x begins.
Note: We don't want to migrate my Spring version, but, want Spring 2.5 to use this JackSon API instead of Spring-Json
Is it possible to replace Spring's JSON support without breaking it ?
Unfortunately, Spring's own documentation states that Spring-json is "deeply" a component of the existing Spring 2.5 framework.
See : http://spring-json.sourceforge.net/
That said - removing the dependencies on spring-json, adding your own JSON parser, and rebuilding spring can be done. I assume this will require a lot of work given that spring-json is a major component of the whole Spring MVC suite.
An alternative : Building a Facade
In addition, I don't know of any Java EE specification for Json libraries which implies that there is a good chance that all internal Spring json dependencies are specific to the APIs defined by Spring-json [compare this, for example, with JPA, which is generically defined by Java EE, so that it is easy to replace many a DAO framework].
Generally, you can package any sort of JSon library as a Spring component that will be available in the application context. Now - if you reimplement the necessary interfaces using the facade pattern, using Jackson under the hood, your version of Spring 2.5 should work the same. Alternatively, you could intercept Json related calls of interest using Spring's aspect oriented injection libraries, and reroute them as necessary.
Again, however, these are all advanced tasks - they would be excellent learning projects but I'm not sure that the time investment would really pay off if this is a production application.
http://www.javaworld.com/javaworld/jw-02-2008/jw-02-springcomponents.html

Categories

Resources