Java EE 6 和替代方案

发布于 2024-10-12 06:51:29 字数 1431 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

奶气 2024-10-19 06:51:29

为什么人们使用 Spring 以及它为何如此流行,需要了解一些历史。

过去,Spring 比 Java EE 应用程序更简单。我参考了 EJB2.x 规范。我感觉到有人对该规范的复杂性进行了反抗。开发人员想要一个更简单的架构,Spring 为他们提供了这一点,允许他们编写 POJO(普通旧 Java 对象),而不是必须实现特定接口才能获得所需功能的类。

Spring 还使 2 个原则变得更加流行:控制反转 (IoC) 和依赖注入。结合起来,这两个原则提供了一种不同的方式来连接应用程序的各个组件,并在应用程序运行时将这些组件放入应用程序中。这与仅编写 POJO 的想法相结合,对许多人来说非常有吸引力,因为代码更简单,并且更容易连接所有组件。

较新的 EJB3 规范取消了 Spring 所提供的一些功能,但 Spring 不仅仅是一个 IoC 容器。它提供了用于 JDBC 访问数据库的出色模板、处理事务的多种简单方法、测试实用程序、MVC 堆栈等。它很受欢迎,并且仍然很受欢迎。我听过的一个笑话是

“EJB3,无人问过的问题的答案……”

EJB3 是一个不错的选择。春天是个不错的选择。 Grails 也是一个不错的选择(在幕后使用 Spring、Hibernate)。

Why people use Spring and why it is so popular requires a little history.

It used to be that Spring was simpler than Java EE applications. I refer to the EJB2.x spec. I get the sense there was sort of a rebellion against the complicated nature of that spec. Developers wanted a simpler architecture, and Spring provided that for them by allowing them to write POJOs (Plain Old Java Objects) instead of classes that had to implement specific interfaces to get the desired functionality.

Spring also made 2 principles more popular: Inversion of Control (IoC) and Dependency Injection. Combined, those two principles provided a different way of wiring up the various components of an application, and getting those components into the application when it ran. That, combined with the idea of just writing POJOs was very compelling for many people, because code was simpler and it was easier to wire up all of you components.

The newer EJB3 spec nullifies some of what Spring has to offer, but Spring is much more than an IoC container. It provides great templates for JDBC access to the database, multiple simple ways of handling transactions, testing utilities, an MVC stack, and so on. It was popular and remains popular. One joke I have heard is

"EJB3, the answer to the question noone asked..."

EJB3 is a fine choice. Spring is a fine choice. Grails is also a fine choice (uses Spring, Hibernate under the covers).

韶华倾负 2024-10-19 06:51:29

“那么,我为什么需要春天呢?”

伊利亚!最后你让我(也希望你自己)相信你不需要 Spring。实际上,这堆东西并没有什么特别好的地方……除非你已经习惯了。他们写了一本关于网络技术的书,然后将计算机科学的其余部分添加到其中,并将其称为 RESTfull。

“但是,想象一下有大量处理表单输入和大量模型的代码。每个控制器可能都有一个视图”。

阿米尔! - 非常好的考虑。我所知道的 Web 框架之间的真正区别在于组件的定义是什么。 Struts 具有三种类型的组件——视图组件、控制器组件和模型组件。乍一看看起来不错(肯定比其他一些好)。但是你可以用这些组件构建什么? - 一页视图、一页控制器和一页模型。天知道从这三行组件中绑定物品的成本是多少——如果可能的话,也许是一个巨大的配置。

真正的解决方案是(正如您在上面引用的实际上所述)是组件的概念,每个组件都有自己的视图、控制器和模型。到目前为止,只有一个框架做到了这一点——HybridJava。 Spring 中的网页构建块是什么?

"So, why do I need spring?"

Ilya! Finally you have convinced me (and hopefully yourself) that you do not need Spring. Actually there is nothing much special good in all this heap ... unless you have already are used to it. They write a book about web technology, then add the rest of computer science into it and call that RESTfull.

"However, imagine having lots of code that handles form input and lots of models. Each controller may have a view".

Amir! - very good consideration. The real difference between web frameworks I know is in what a definition of component is. Struts has three types of components - View, Controler and Model components. At first glance looks good (better than some others for sure). But what can you build of those components? - One page View, one Page Controller and one page Model. God knows what will be the cost of binding items from these three rows of components - maybe a huge configuration if at all possible.

The real solution is (as you practically stated in the quoted above) is a concept of components that each has its view, its controller and its model. Only one framework went that far so far - HybridJava. What is a web page building block in Spring?

南渊 2024-10-19 06:51:29

听起来您需要使用 Spring 然后使用 Java EE 6 来 POC 特定功能,这样您就可以将两者与真实的实用原型进行比较。

然而,我使用 spring 的原因是:

  • 能够将我的应用程序从应用程序服务器中抽象出来。因此,我可以在任何应用程序服务器上运行,或者在 AS 之外运行,以对
  • 我必须编写的大量样板代码进行单元测试,以改进我的设计,
  • IOC/DI 已经可用 - 需要依赖项的对象不知道如何获得它们——它只知道它需要什么接口。一些第三方提供它们。是的,您可以在 Java EE 6 中推出您自己的第三方版本,但它已经在 Spring 中提供。
  • Bean 管理的事务 - Spring 提供了对事务进行完全低级别控制所需的所有工具。我始终建议使用 BMT,因为它为您提供了可能需要的灵活性。

Sounds like you need to POC particular capabilities with Spring and then with Java EE 6 so you can compare the two like for like with a real working practical prototype.

The reasons I use spring however, are:

  • ability to abstract my application away from the application server. I can thus run on any application server, or outside of AS for unit testing
  • a lot of the boiler plate code that I would have to write, to improve my design is already available
  • IOC/DI - the object that needs dependencies does not know about how to get them - all it knows is what interfaces it requires. Some third party provides them. Yes, you could roll your own version of this third party in Java EE 6 but it is already available in Spring.
  • Bean Managed Transactions - Spring provides all the tools you need to have complete low level control on your transactions. I would always suggest using BMT as it gives you the flexibility you might need.
青芜 2024-10-19 06:51:29

Spring 对于 Java EE 来说不是必需的。 Spring 只是让复杂的 Java EE 组件变得易于使用。

Spring is not necessary to Java EE. Spring just makes complex Java EE components easy to use.

情未る 2024-10-19 06:51:29

Spring 是一个模型-视图-控制器,它使 Java EE 更干净、更有组织。从结构上来说,将模型、视图和控制器分开是更正确的。

我同意你的看法。如果它是一个简单的网站,那么我认为您可以仅使用 Java EE 完成所有操作。然而,想象一下有大量处理表单输入和大量模型的代码。每个控制器可以有一个视图。您可以创建一个 servlet,然后转发到正确的 jsp 页面,或者您可以使用 spring,因为它已经完成了所有这些工作。

您可以决定需要使用多少弹簧。一个好的框架可以让您选择要使用的部分。我认为 spring 做得很好,因为你可以使用 mvc 模型或者更进一步,用它做更多事情。

最后一件事,Spring 具有依赖注入,这使得配置变得更加容易。

Spring a model-view-controller that makes Java EE cleaner and more organized. It is structurally more correct to separate your models, views and controller.

I agree with you. If it is a simple website then I think you can do everything with just Java EE. However, imagine having lots of code that handles form input and lots of models. Each controller may have a view. You can create a servlet and then forward to the correct jsp page, or you can use spring because it already does all of this.

The decision is your of how much you need to use spring. A good framework is one that lets you pick and choose what parts to use. I think spring does this well because you can just use the mvc model or go further and do more with it.

Final thing, spring has dependency injection which makes configuration much easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文