I am very confused with different java frameworks. I want to create a java server project to offer some Restful web-service, but I really dont know which framework I should choose. What is the difference between JSF, EJB, Hibernate and Spring? Please help me understand them more.
-
7@MichaelLaffargue Depending on where you eat, there may not be as much difference between a burger and a horse as you think. – Jason C Feb 25 '14 at 03:08
-
2@JasonC You got a point there ;) – Michael Laffargue Feb 25 '14 at 07:37
4 Answers
These are frameworks for different layers.
JSF is for the view (web) layer, it's a component oriented framework (every part of a page is a component, it has state) like Wicket or Tapestry, and unlike Action frameworks like Spring MVC, Struts or Stripes
Books: Core JavaServer Faces (3rd Edition)
Tutorials: CoreServlets.comEJB 3.x is a container that's part of the JavaEE stack. It does things like dependency injection and bean lifecycle management. You usually need a full JavaEE application server for EJB3
Tutorials: JavaEE 6 Tutorial: EJB
Books: EJB 3 in ActionSpring is also a container, but Spring can run in any java code (a simple main class, an applet, a web app or a JavaEE enterprise app). Spring can do almost everything EJB can do and a lot more, but I'd say it's most famous for dependency injection and non-intrusive transaction management
Online Reference (excellent)
Books: I couldn't find a good english book on Spring 3.x, although several are in the makingHibernate was the first big ORM (Object relational mapper) on the Java Platform, and as such has greatly inspired JPA (which is part of the EJB3 standard but can be used without an EJB container). I would suggest coding against JPA and only using hibernate as a provider, that way you can easily switch to EclipseLink etc.
Books: Pro JPA 2: Mastering the Java™ Persistence API (not hibernate-specific),
Java Persistence with Hibernate (getting a bit old)

- 292,901
- 67
- 465
- 588
-
9To state explicitly, Spring just needs the JVM where as EJB needs a full app server – boardtc Feb 22 '12 at 21:07
-
@boardtc Spring needs at least a servlet container, no? AFAIK, Spring uses an embedded Tomcat instance. – Utku Apr 28 '17 at 10:10
-
2@Utku Spring MVC does, but Spring is much more than an MVC framework – Sean Patrick Floyd Apr 28 '17 at 10:40
- JSF: a GUI framework - you don't need this if you only want to implement a backend
- EJB: a standard for distributed components, used to be horribly complex, but version 3 of the standard is quite easy to use. This could be part of your solution.
- Hibernate: An Object-relational mapping framework. It served as the inspiration for the JPA (Java Persistence Architecture) standard, which is now supported by both Hibernate and EJBs.
- Spring: An application framework that does all kinds of things, among them dependency injection, web GUIs and AOP.
However, if you want to do REST, then the most important standard for you is JAX-RS. You can use it either within the Spring framework or with EJBs. For persistence, you could use Hibernate, or the JPA implementation of an EJB container such as Glassfish

- 292,901
- 67
- 465
- 588

- 342,105
- 78
- 482
- 720
EJB is an Enterprise Java Bean -- see link for description, but basically its the 'default' java way of writing an enterprise application.
Hibernate is an ORM Framework; a way to map the Objects/Classes in your application to database tables. It is related to how you persist your data to a database.
Spring is an IoC/Dependency Injection container that provides many useful and well tested abstractions to make your life easier. Spring is sort of like its own application framework.
JSF is Java Server Faces, a view technology for java web applications.
You would use either EJB OR Spring. You could use Hibernate as your persistence implementation, if you wanted, with either; you do not need to do this. For RESTFul webservices, you don't really need JSF.
People are very happy with Spring - I recommend using that...

- 118,147
- 33
- 203
- 236
- JSF - Java Server Faces -> Web User Interface
- EJB - Enterprise Java Beans -> Components which are stateful (session oriented) or stateless (services), message driven (asynchronous)
- Hibernate - Persistence Service like other JPA implementations (Eclipselink,OpenJPA or Toplink)
- Spring is another world without EJBs, which is able to integrate other view technologies. It's quite flexible.
You have to decide between JEE5/6 and spring. Take the red or the blue pill don't use both.

- 4,427
- 8
- 43
- 72

- 68,052
- 28
- 140
- 210
-
2Nice overview. But about red or blue pills: Spring integrates nicely with almost any other technology, including EJB http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ejb.html – Sean Patrick Floyd Nov 26 '10 at 08:00