Spring 如何融入我的应用程序架构?

发布于 2024-09-09 02:24:45 字数 596 浏览 7 评论 0原文

我目前正在使用 Java 重建现有的 PHP 应用程序。因此,我有一个现有的前端 GUI 和一个正在使用的现有数据库模式。

这是我正在努力的技术堆栈:

  1. jQuery、客户端
  2. Wicket、前端
  3. Spring、???
  4. Hibernate、ORM
  5. MySQL、数据库

在阅读 Wicket In Action 和 Hibernate 文档中有关 Spring 的内容之前,我设想将两者连接起来通过我自己的业务逻辑一起。我有使用 JBoss Seam 的经验,但我被告知 Spring 几乎没有可比性(尽管文档表明不然,IMO)。没有在我的阅读清单中添加一本关于 Spring 的书(我还没有找到一本合适的、评论不错的书),我不知所措。

Spring 会在此技术堆栈中提供哪些好处?

主观与客观可选的后续问题:什么参考材料(书籍、网站等)可以帮助我开始使用 Spring 3 中我可以使用的部分?

I'm currently rebuilding an existing PHP application using Java. I therefore have an existing frontend GUI and an existing database schema that I'm working with.

Here is the technology stack I'm working towards:

  1. jQuery, client-side
  2. Wicket, front-end
  3. Spring, ???
  4. Hibernate, ORM
  5. MySQL, database

Before reading about Spring in both Wicket In Action and the Hibernate documentation, I envisioned wiring the two together through my own business logic. I have experience with JBoss Seam, but am told that Spring is hardly comparable (although the documentation suggests otherwise, IMO). Short of adding a book about Spring to my reading list (I haven't found an appropriate one with good reviews yet), I'm at a loss.

What benefit(s) will Spring provide in this technology stack?

Subjective & optional follow up question: what reference material (book, website, etc) will get me started with the portion of Spring 3 I may utilize?

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

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

发布评论

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

评论(4

俏︾媚 2024-09-16 02:24:45

首先,您可以在没有 Spring 的情况下创建 Web 应用程序。但 Spring 会极大地方便事情。 Spring框架是一个轻量级、非侵入性的。春天就像一种导体。 Spring 在以下方面可以帮助您:

  1. 保持对象松散耦合。这将使您的应用程序更加灵活并且对未来的更改持开放态度

  2. 通过AOP(面向方面​​编程)对事务的强大支持。

  3. 对象关系映射 (ORM) 集成模块。 Spring 并不尝试实现自己的 ORM 解决方案,但确实提供了几个流行的 ORM 框架的挂钩,包括 Hibernate、Java Persistence API、Java Data Objects 和 iBATIS SQL Maps。 Spring 的事务管理支持每个 ORM 框架以及 JDBC。

  4. Spring MVC 框架。尽管 Spring 与多个流行的 MVC 框架集成,但它还附带了自己非常强大的 MVC 框架,可以在应用程序的 Web 层中推广 Spring 的松散耦合技术。

一本关于Spring的好书:Pro Spring

First, you can make your web application without Spring. But Spring will greatly facilitate things. Spring framework is a lightweight, non-invasive. Spring is like a kind of conductor. Among other things Spring helps you in:

  1. To keep your objects loosely coupled. This will make your application more flexible and open to future changes

  2. Powerful support for transactions through the AOP (Aspect Oriented Programming).

  3. Object-relational mapping (ORM) integration module. Spring doesn’t attempt to implement its own ORM solution, but does provide hooks into several popular ORM frameworks, including Hibernate, Java Persistence API, Java Data Objects, and iBATIS SQL Maps. Spring’s Transaction management supports each of these ORM frameworks as well as JDBC.

  4. The Spring MVC framework. Even though Spring integrates with several popular MVC frameworks, it also comes with its own very capable MVC framework that promotes Spring’s loosely coupled techniques in the web layer of an application.

A good book about Spring: Pro Spring

你对谁都笑 2024-09-16 02:24:45

Spring,正如这篇评论中所述,是非-侵入性的。它只是连接您的应用程序组件。并提供有用的类,使使用其他框架(JMS、JPA 等)变得更容易。 Spring 不会强迫您在任何地方使用它的类或接口。

它处理的是组件(对象)的创建,以便您可以引用类的依赖项,而无需实例化它们。也就是说,你说的是你的类需要什么,而不是它如何获取它。这使得应用程序非常灵活。

简而言之 - 要了解更多信息,请阅读链接的文章。这与最新版本无关,但这并不重要。

Spring, as noted in this review is non-invasive. It just wires your application components. And provides useful classes that make using other frameworks easier (JMS, JPA, etc). Spring doesn't force you to use its classes or interfaces anywhere.

What it handles is the creation of your components (objects), so that you can refer to a class' dependencies, without instantiating them. I.e. you say what your class needs, not how it is obtaining it. This makes the application very flexible.

That's in short - for more, read the linked article. It's not about the latest version, but that doesn't matter.

多情出卖 2024-09-16 02:24:45

除了依赖注入之外,Spring 还提供声明式事务管理、与 ORM 的简单集成、面向方面的编程支持和许多其他好东西等功能。

有关文档,请参阅 Spring 参考:http://static。 springsource.org/spring/docs/3.0.x/spring-framework-reference/html

In addition to dependency injection, Spring offers features like declarative transaction management, simple integration with ORM, aspect-oriented programming support and many other nice things.

For documentation see Spring reference: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html

醉酒的小男人 2024-09-16 02:24:45

@Dolph,用最简单的术语来说,将 Spring 视为最高程度的应用程序框架。这个“框架”提供了几个“组件桶”,您可以在其中轻松插入不同类型的实现。例如,对于 ORM,您可以选择使用 Hibernate 而不是 JPA 或 TopLink;对于前端,您可以选择使用 Wicket 而不是 Struts 或 SpringMVC,等等。

这样做的全部优点(除了其他帖子中提到的所有好处之外)是它允许您将来轻松地更换任何这些实现​​。因此,有一天您基本上可以将 Hibernate 剔除并用 TopLink 替换,并且它永远不会对其他组件造成连锁反应。

使用 Spring 的另一个好处是,您的代码变得不再那么混乱,并且与其他类的依赖关系也变得松散,因为您自己创建新对象的时间更少,Spring 会为您处理这些问题。也就是说,您很快就会意识到测试代码是多么容易,因为要测试的 API 变得非常原子。这是人们在编写测试用例时灰心丧气的主要原因之一,因为他们很快意识到,为了测试一个 API,他们必须构建很多东西来测试它。因此,整个过程很脆弱,想象一下,如果您更改该 API,则需要在再次测试之前重建所有内容。

Pro Spring 的书很好,@JLBarros 提到过。我非常喜欢Spring in Action。当我第一次开始使用 Spring 时,它非常容易阅读。这可能是我熟读的一本参考书。

@Dolph, in the simplest term, think of Spring as your application framework at the highest degree. This "framework" provides several "component buckets" where you can easily plug in different types of implementations. For example, for ORM, you may choose to use Hibernate over JPA or TopLink, for front end, you may choose Wicket over Struts or SpringMVC, and so forth.

The whole beauty of this (besides all the goodies stated in other posts) is it allows you easily swap out any of these implementations easily in the future. So, you can essentially rip out Hibernate one day and replace with TopLink, and it will never cause ripple effect to other components.

Another beauty of using Spring is your code becomes less clutter and has loose dependencies with other classes because you spend less time creating new objects yourself, Spring handles that for you. That said, you will quickly realize how easy for you to test your code because your API to be tested becomes very atomic. This is one primary reason why folks get discouraged in writing testcases, because they quickly realize that in order for them to test one API, they have to construct whole lot of things just to test that. Because of that, the whole process is brittle, imagine if you change that API, you need to reconstruct everything before testing it again.

Pro Spring book is good, mentioned by @JLBarros. I like Spring in Action very much. It is very very easy to read when I first got started with Spring. This is probably one reference book that I read from skin to skin.

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