Introducing the Spring FrameWork

2008-02-23 10:06:48来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

Yet another Framework?

You may be thinking "not another framework." Why should you bother to read this article, or download the Spring Framework, when there are already many open source (and proprietary) J2EE frameworks?

I believe that Spring is unique, for several reasons:

  • It addresses areas that many other popular frameworks don't. Spring focuses around providing a way to manage your business objects.

  • Spring is both comprehensive and modular. Spring has a layered architecture, meaning that you can choose to use just about any part of it in isolation, yet its architecture is internally consistent. So you get maximum value from your learning curve. You might choose to use Spring only to simplify use of JDBC, for example, or you might choose to use Spring to manage all your business objects.

  • It's designed from the ground up to help you write code that's easy to test. Spring is an ideal framework for test driven projects.

Spring is not necessarily one more framework dependency for your project. Spring is potentially a one-stop shop, addressing most infrastructure concerns of typical applications. It also goes places other frameworks don't.

Although it has been an open source project only since February 2003, Spring has a long heritage. The open source project started from infrastructure code published with my book, Expert One-on-One J2EE Design and Development, in late 2002. Expert One-on-One J2EE also laid out the basic architectural thinking behind Spring. However, the architectural concepts go back to early 2000, and reflect my experience in developing infrastructure for a series of successful commercial projects.

Since January 2003, Spring has been hosted on SourceForge. There are now ten developers, of whom six are highly active.


Architectural benefits of Spring

Before we get down to specifics, let's look at some of the benefits Spring can bring to a project:

  • Spring can effectively organize your middle tier objects, whether or not you choose to use EJB. Spring takes care of plumbing that would be left up to you if you use only Struts or other frameworks geared to particular J2EE APIs.

  • Spring can eliminate the proliferation of Singletons seen on many projects. In my experience, this is a major problem, reducing testability and object orientation.

  • Spring can eliminate the need to use a variety of custom properties file formats, by handling configuration in a consistent way throughout applications and projects. Ever wondered what magic property keys or system properties a particular class looks for, and had to read the Javadoc or even source code? With Spring you simply look at the class's JavaBean properties. The use of Inversion of Control (discussed below) helps achieve this simplification.

  • Spring can facilitate good programming practice by reducing the cost of programming to interfaces, rather than classes, almost to zero.

  • Spring is designed so that applications built with it depend on as few of its APIs as possible. Most business objects in Spring applications have no dependency on Spring.

  • Applications built using Spring are very easy to unit test.

  • Spring can make the use of EJB an implementation choice, rather than the determinant of application architecture. You can choose to implement business interfaces as POJOs or local EJBs without affecting calling code.

  • Spring helps you solve many problems without using EJB. Spring can provide an alternative to EJB that's appropriate for many Web applications. For example, Spring can use AOP to deliver declarative transaction management without using an EJB container; even without a JTA implementation, if you only need to work with a single database.

  • Spring provides a consistent framework for data Access, whether using JDBC or an O/R mapping product such as Hibernate.

Spring really can enable you to implement the simplest possible solution to your problems. And that's worth a lot.


What does Spring do?

Spring provides a lot of functionality, so I'll quickly review each major area in turn.


Mission statement

Firstly, let's be clear on Spring's scope. Although Spring covers a lot of ground, we do have clear vision as to what it should and shouldn't address.

Spring's main aim is to make J2EE easier to use and promote good programming practice.

Spring does not reinvent the wheel. Thus you'll find no logging packages in Spring, no connection pools, no distributed transaction coordinator. All these things are provided by open source projects (such as Commons Logging, which we use for all our log output, or Commons DBCP), or by your application server. For the same reason, we don't provide an O/R mapping layer. There are good solutions to this problem such as Hibernate and JDO.

Spring does aim to make existing technologies easier to use. For example, although we are not in the business of low-level transaction coordination, we do provide an abstraction layer over JTA or any other transaction strategy.

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:关于TOMCAT APACHE整合后的servlet应用!

下一篇:《Java 手机/PDA 程序设计入门》读书笔记2