Java EE or Spring for PrimeFaces project - any difference? - spring

I'm planning a project which will use Primefaces to generate its UI.
I understand that PrimeFaces as JSF library is somewhat more at home with Java EE than Spring, although there seems to be a lot of examples of using it together with Spring.
Are there any notable disadvantages of using Spring instead of Java EE for the DAO and service layer in a PrimeFaces project?

It complicates the things, Java EE is complex enough for application developers(you need time to open dark parts and see the lights or i hope it:)) so my opinion if you don't have a requirement about it, don't use Spring and JSF together to better understand your bean lifecycle. You can find good dicussion in this source. I prefer to use HTML+Bootstrap and Spring MVC or use Seam Framework for JSF or no framework just use pure Java EE support with primafaces(JSF) can be good.

Related

Spring MVC vs Java EE

So I'm about to learn Spring MVC. But what I don't understand is why should I use Spring MVC if I can implement the MVC pattern using a single servlet conroller and JSPs? What advantages does Spring MVC provide over simple java MVC pattern?
Actually yes, you can do it. Question is if you should do it. Spring MVC gives you better organization of your code.
Pure MVC Frameworks like Spring MVC are obsolete today. When combined with templating engines like Thymeleaf, it lacks functionality and developers usually reinvent JSF. For single-page apps based on some popular JS frameworks that need REST backend, JAX-RS is way cleaner and better than Spring MVC REST.
So no, today you don't need Spring MVC and can stick with pure Java EE. For simple, toy-like applications where servlets are enough, you don't really need it but it may be better to use it. For anything serious, MVC is outdated and Spring has nothing to offer.
Edit 2017: Spring offers JAX-RS integration. However, it has several pitfalls, for example Spring won't automatically register classes annotated with #Path for you. Details can be found in Dzone Article
The best way to realize that it's better to play with these technologies for yourself, if you want to try spring MVC I recommend you start with spring boot because you can create projects with more agility without configuring xml files
Spring Boot
Some Features
Create stand-alone Spring applications
Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
Provide opinionated 'starter' POMs to simplify your Maven configuration
Automatically configure Spring whenever possible
Provide production-ready features such as metrics, health checks and
externalized configuration
Absolutely no code generation and no requirement for XML configuration
One of the ideas applied in Spring (not invented by Spring) is
Do not reinvent a wheel.
Having a single controller is not a good idea I'd say - breaking separation of concerns principle.
You can learn more about MVC from Spring documentation.

How to integrate Spring AOP in CDI - any examples

I would implement a Spring aspect in a j2ee application, can someone post some tutorials?
I've just used Spring in web application but I've not idea how to invoke a cross cutting concern in CDI container.
Thanks in advance
Is there a special need for combining Spring and CDI? If not, I'd suggest to stick to standard Java EE as long as you can solve your problem with it and only if not, look for external components (and even then, you should first check the "sort-of-standard" CDI extensionf from the Apache Deltaspike project.
Cross-cutting concerns can be solved via pure CDI - check our for example the Java EE 7 tutorial about the topic.
Small note: Don't use J2EE anymore if not maintaining an ancient application.

Whats the difference between Spring and Spring MVC?

I know this is not a programmatic questions.
I am a n00b to this area coming from Java EE background and could not find the difference between the two online (may be I am not a good surfer)
Could someone please share the info?
Spring is a framework alternative to Java EE with three parts:
Dependency injection
Aspect oriented programming.
Libraries for web MVC, persistence, messaging, etc.
Spring MVC is for web MVC. It's one of the many libraries built into Spring. You can use other alternatives (e.g. Struts, SEAM, etc.) if you wish and still use Spring.
spring is enterprise framework designed to solve all your problems for enterprise applications. At present they call it as Spring IO, which can be found at spring.io website.
However, Spring MVC is a framework part of the whole stack available to solve the enterprise solutions. This is framework for writing web applications.

CDI-like conversation scope in Spring

I've been developing Spring 3 + JSF 2.0 applications for some time. They run on simple Tomcat or Jetty container. Looking ad CDI I envy a conversation scope.
Are you aware of simple conversation scope implementation for Spring? I don't want to use full-blown SpringMVC + WebFlow + SpringFaces stack. I just need a web filter that enables conversation scope and lets me inject conversation object and start or stop it. Like in CDI.
Not exactly on your question, but since you're asking for a solution in order to avoid using Spring Webflow, Spring Faces, etc ... it looks like you're using Spring just for DI (i mean you're not so dependent on the Spring ecosystem). Well, maybe in this case it would worth the effort to think about migrating to a Java EE 6 stack. I don't think the migration would be that difficult, since you're using not that much from Spring, and in case you have beans in spring you still need, you could write some CDI producers for them. You can google for some migration paths from Spring to Java EE 6.
And if you're afraid of the "heavy Java EE containers", well jboss 7.1, Glassfish 3.1.2 and TomEE all start on my notebook in under 2 seconds, and I bet your tomcat + spring container don't start much faster.
Just my opinion.
you should give a look to Apache TomEE + CODI project (subject of Apache MyFaces) and/or Apache Deltaspike (not sure the doc is up to date because it is pretty young)
TomEE gives you the strength of CDI and CODI adds a small integration layer between cdi and jsf to make it very powerful (it will be integrated in deltaspike but that's still a bit in progress)
MyFaces Orchestra (also works with Mojarra) is currently the best conversation scope implementation for JSF 2.0 on top of Spring.
Use the JSF #ViewScoped annotation on your managed bean that gives you the same conversation-like semantics as the CDI conversation scope. One difference between CDI's conversation scope and JSF's view scope is that CDI gives you explicit and straightforward control over the conversation while the JSF viewscope is pretty much canned for use. But with JSF's ViewScope, you know exactly where the boundaries of a conversation are: A conversation starts when you load a page backed with a #ViewScoped bean and ends when the page is closed. This is convenient for many use cases
Cagatay of primefaces also has this hack to simulate the CDI scope in Spring.
This tutorial by Max Katz from the the Richfaces team also gives a good intro the JSF ViewScope

Spring can be used in Seam?

I understand that Spring has really nice features, such as dependency injection. I am new to Spring. I have understood that I can use Spring alongside with struts and other frameworks too, in order to use its capabilities.
In my project I am going to use Seam 2.0, I am using JNDI to lookup for the EJBs. I am wondering if I can integrate Spring with Seam and use its ApplicationContext in order to get beans from that directly and not use JNDI lookup anymore?
There is a whole chapter in the Seam reference dedicated to this:
27. Spring Framework integration

Resources