EJB,hibernate,spring和JSF有什么区别?

时间:2021-07-15 15:46:57

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.

我对不同的java框架非常困惑。我想创建一个java服务器项目来提供一些Restful web服务,但我真的不知道我应该选择哪个框架。 JSF,EJB,Hibernate和Spring有什么区别?请多帮我理解一下。

4 个解决方案

#1


51  

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

    JSF用于视图(web)层,它是面向组件的框架(页面的每个部分都是一个组件,它具有状态),如Wicket或Tapestry,与Spring框架,如Spring MVC,Struts或Stripes不同

    Books: Core JavaServer Faces (3rd Edition)
    Tutorials: CoreServlets.com

    书籍:核心JavaServer Faces(第3版)教程:CoreServlets.com

  • EJB 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

    EJB 3.x是JavaEE堆栈的一部分容器。它执行依赖注入和bean生命周期管理等操作。您通常需要EJB3的完整JavaEE应用程序服务器

    Tutorials: JavaEE 6 Tutorial: EJB
    Books: EJB 3 in Action

    教程:JavaEE 6教程:EJB Books:EJB 3 in Action

  • Spring 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

    Spring也是一个容器,但Spring可以在任何java代码(一个简单的主类,一个applet,一个web应用程序或一个JavaEE企业应用程序)中运行。 Spring可以做几乎所有EJB可以做的事情以及更多,但我会说它最有名的是依赖注入和非侵入式事务管理

    Online Reference (excellent)
    Books: I couldn't find a good english book on Spring 3.x, although several are in the making

    在线参考(优秀)书籍:我在Spring 3.x上找不到一本好的英语书籍,虽然有几本正在制作中

  • Hibernate 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.

    Hibernate是Java平台上的第一个大型ORM(对象关系映射器),因此极大地激发了JPA(它是EJB3标准的一部分,但可以在没有EJB容器的情况下使用)。我建议对JPA进行编码,只使用hibernate作为提供者,这样你就可以轻松切换到EclipseLink等。

    Books: Pro JPA 2: Mastering the Java™ Persistence API (not hibernate-specific),
    Java Persistence with Hibernate (getting a bit old)

    书籍:Pro JPA 2:掌握Java™Persistence API(不是特定于hibernate),Java Persistence with Hibernate(有点旧)

#2


6  

  • JSF: a GUI framework - you don't need this if you only want to implement a backend
  • JSF:GUI框架 - 如果您只想实现后端,则不需要这样做
  • 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.
  • EJB:分布式组件的标准,过去非常复杂,但标准的第3版非常容易使用。这可能是您解决方案的一部分。
  • 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.
  • Hibernate:一个对象关系映射框架。它是JPA(Java持久性架构)标准的灵感来源,现在Hibernate和EJB都支持它。
  • Spring: An application framework that does all kinds of things, among them dependency injection, web GUIs and AOP.
  • Spring:一个执行各种操作的应用程序框架,其中包括依赖注入,Web GUI和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

但是,如果你想做REST,那么最重要的标准就是JAX-RS。您可以在Spring框架内或使用EJB。对于持久性,您可以使用Hibernate或EJB容器(如Glassfish)的JPA实现

#3


4  

EJB is an Enterprise Java Bean -- see link for description, but basically its the 'default' java way of writing an enterprise application.

EJB是一个企业Java Bean - 请参阅描述链接,但基本上是编写企业应用程序的“默认”Java方式。

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.

Hibernate是一个ORM框架;一种将应用程序中的对象/类映射到数据库表的方法。它与您将数据保存到数据库的方式有关。

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.

Spring是一个IoC / Dependency Injection容器,它提供了许多有用且经过良好测试的抽象,使您的生活更轻松。 Spring有点像它自己的应用程序框架。

JSF is Java Server Faces, a view technology for java web applications.

JSF是Java Server Faces,一种用于Java Web应用程序的视图技术。

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.

您可以使用EJB或Spring。您可以使用Hibernate作为持久性实现,如果您愿意,可以使用;你不需要这样做。对于RESTFul webservices,您并不真正需要JSF。

People are very happy with Spring - I recommend using that...

人们对Spring非常满意 - 我建议使用它......

#4


2  

  • JSF - Java Server Faces -> Web User Interface
  • JSF - Java Server Faces - > Web用户界面
  • EJB - Enterprise Java Beans -> Components which are stateful (sessioen oriented) or statles (services), message driven (asynchronous)
  • EJB - Enterprise Java Bean - >有状态(面向sessioen)或statles(服务),消息驱动(异步)的组件
  • Hibernate - Persistence Service like other JPA implementations (Eclipselink,OpenJPA or Toplink)
  • Hibernate - 像其他JPA实现一样的持久性服务(Eclipselink,OpenJPA或Toplink)
  • Spring is another world without EJBs, which is able to integrate other view technologies. It's quit flexible.
  • Spring是另一个没有EJB的世界,它能够集成其他视图技术。它退出了灵活性。

You have to decide between JEE5/6 and spring. Take the red or the blue pill don't use both.

你必须在JEE5 / 6和spring之间做出决定。服用红色或蓝色药丸不要同时使用。

#1


51  

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

    JSF用于视图(web)层,它是面向组件的框架(页面的每个部分都是一个组件,它具有状态),如Wicket或Tapestry,与Spring框架,如Spring MVC,Struts或Stripes不同

    Books: Core JavaServer Faces (3rd Edition)
    Tutorials: CoreServlets.com

    书籍:核心JavaServer Faces(第3版)教程:CoreServlets.com

  • EJB 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

    EJB 3.x是JavaEE堆栈的一部分容器。它执行依赖注入和bean生命周期管理等操作。您通常需要EJB3的完整JavaEE应用程序服务器

    Tutorials: JavaEE 6 Tutorial: EJB
    Books: EJB 3 in Action

    教程:JavaEE 6教程:EJB Books:EJB 3 in Action

  • Spring 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

    Spring也是一个容器,但Spring可以在任何java代码(一个简单的主类,一个applet,一个web应用程序或一个JavaEE企业应用程序)中运行。 Spring可以做几乎所有EJB可以做的事情以及更多,但我会说它最有名的是依赖注入和非侵入式事务管理

    Online Reference (excellent)
    Books: I couldn't find a good english book on Spring 3.x, although several are in the making

    在线参考(优秀)书籍:我在Spring 3.x上找不到一本好的英语书籍,虽然有几本正在制作中

  • Hibernate 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.

    Hibernate是Java平台上的第一个大型ORM(对象关系映射器),因此极大地激发了JPA(它是EJB3标准的一部分,但可以在没有EJB容器的情况下使用)。我建议对JPA进行编码,只使用hibernate作为提供者,这样你就可以轻松切换到EclipseLink等。

    Books: Pro JPA 2: Mastering the Java™ Persistence API (not hibernate-specific),
    Java Persistence with Hibernate (getting a bit old)

    书籍:Pro JPA 2:掌握Java™Persistence API(不是特定于hibernate),Java Persistence with Hibernate(有点旧)

#2


6  

  • JSF: a GUI framework - you don't need this if you only want to implement a backend
  • JSF:GUI框架 - 如果您只想实现后端,则不需要这样做
  • 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.
  • EJB:分布式组件的标准,过去非常复杂,但标准的第3版非常容易使用。这可能是您解决方案的一部分。
  • 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.
  • Hibernate:一个对象关系映射框架。它是JPA(Java持久性架构)标准的灵感来源,现在Hibernate和EJB都支持它。
  • Spring: An application framework that does all kinds of things, among them dependency injection, web GUIs and AOP.
  • Spring:一个执行各种操作的应用程序框架,其中包括依赖注入,Web GUI和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

但是,如果你想做REST,那么最重要的标准就是JAX-RS。您可以在Spring框架内或使用EJB。对于持久性,您可以使用Hibernate或EJB容器(如Glassfish)的JPA实现

#3


4  

EJB is an Enterprise Java Bean -- see link for description, but basically its the 'default' java way of writing an enterprise application.

EJB是一个企业Java Bean - 请参阅描述链接,但基本上是编写企业应用程序的“默认”Java方式。

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.

Hibernate是一个ORM框架;一种将应用程序中的对象/类映射到数据库表的方法。它与您将数据保存到数据库的方式有关。

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.

Spring是一个IoC / Dependency Injection容器,它提供了许多有用且经过良好测试的抽象,使您的生活更轻松。 Spring有点像它自己的应用程序框架。

JSF is Java Server Faces, a view technology for java web applications.

JSF是Java Server Faces,一种用于Java Web应用程序的视图技术。

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.

您可以使用EJB或Spring。您可以使用Hibernate作为持久性实现,如果您愿意,可以使用;你不需要这样做。对于RESTFul webservices,您并不真正需要JSF。

People are very happy with Spring - I recommend using that...

人们对Spring非常满意 - 我建议使用它......

#4


2  

  • JSF - Java Server Faces -> Web User Interface
  • JSF - Java Server Faces - > Web用户界面
  • EJB - Enterprise Java Beans -> Components which are stateful (sessioen oriented) or statles (services), message driven (asynchronous)
  • EJB - Enterprise Java Bean - >有状态(面向sessioen)或statles(服务),消息驱动(异步)的组件
  • Hibernate - Persistence Service like other JPA implementations (Eclipselink,OpenJPA or Toplink)
  • Hibernate - 像其他JPA实现一样的持久性服务(Eclipselink,OpenJPA或Toplink)
  • Spring is another world without EJBs, which is able to integrate other view technologies. It's quit flexible.
  • Spring是另一个没有EJB的世界,它能够集成其他视图技术。它退出了灵活性。

You have to decide between JEE5/6 and spring. Take the red or the blue pill don't use both.

你必须在JEE5 / 6和spring之间做出决定。服用红色或蓝色药丸不要同时使用。