Java EJB、hibernate、spring 和 JSF 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4281304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between EJB, hibernate, spring and JSF?
提问by user261002
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-service,但我真的不知道我应该选择哪个框架。JSF、EJB、Hibernate 和 Spring 之间有什么区别?请帮助我更多地了解它们。
采纳答案by Sean Patrick Floyd
These are frameworks for different layers.
这些是不同层的框架。
JSFis 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.xis a container that's part of the JavaEEstack. 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 ActionSpringis 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 makingHibernatewas 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)
JSF用于视图(Web)层,它是一个面向组件的框架(页面的每个部分都是一个组件,它具有状态),如 Wicket 或 Tapestry,与 Spring MVC、Struts 或 Stripes 等 Action 框架不同
EJB 3.x是一个容器,它是JavaEE堆栈的一部分。它执行诸如依赖注入和 bean 生命周期管理之类的事情。您通常需要一个用于 EJB3 的完整 JavaEE 应用服务器
教程:JavaEE 6 教程:EJB
书籍:EJB 3 实战Spring也是一个容器,但 Spring 可以在任何 Java 代码中运行(简单的主类、小程序、Web 应用程序或 JavaEE 企业应用程序)。Spring 几乎可以做 EJB 可以做的几乎所有事情,而且还有更多,但我认为它最著名的是依赖注入和非侵入式事务管理
在线参考(优秀)
书籍:我找不到关于 Spring 3.x 的好的英文书,虽然有几本正在制作中Hibernate是Java 平台上第一个大型ORM(对象关系映射器),因此极大地启发了JPA(它是 EJB3 标准的一部分,但可以在没有 EJB 容器的情况下使用)。我建议针对 JPA 进行编码,并且仅使用 hibernate 作为提供程序,这样您就可以轻松切换到 EclipseLink 等。
书籍:Pro JPA 2:精通 Java?Persistence API(不是特定于休眠的),
Java Persistence with Hibernate(有点老了)
回答by hvgotcodes
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 网络服务,您并不真正需要 JSF。
People are very happy with Spring - I recommend using that...
人们对 Spring 非常满意 - 我建议使用它......
回答by stacker
- 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.
- JSF - Java Server Faces -> Web 用户界面
- EJB - Enterprise Java Beans -> 有状态(面向会话)或无状态(服务)、消息驱动(异步)的组件
- Hibernate - 像其他 JPA 实现(Eclipselink、OpenJPA 或 Toplink)一样的持久化服务
- 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 之间做出决定。服用红色或蓝色药丸,不要同时使用两者。
回答by Michael Borgwardt
- 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.
- JSF:一个 GUI 框架 - 如果您只想实现一个后端,则不需要它
- EJB:分布式组件的标准,过去非常复杂,但该标准的第 3 版非常易于使用。这可能是您解决方案的一部分。
- Hibernate:一个对象关系映射框架。它是 JPA(Java 持久性架构)标准的灵感来源,现在 Hibernate 和 EJB 都支持该标准。
- 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 实现