| By Rick Hightower | Article Rating: |
|
| January 8, 2005 12:00 AM EST | Reads: |
81,585 |
If you have not looked into Spring yet, it is time. Here is why you should!
Grady Booch once said that the great thing about objects is that they can be replaced. The great thing about Spring is it helps you replace them. With Spring, you simply inject collaborating objects called dependencies using JavaBeans properties and configuration files. Then it's easy enough to switch out collaborating objects when you need to. Spring allows you to dynamically add services to objects called aspects. This is similar to the Decorator Design pattern, but does not require you to recompile your code base to apply these services. This allows you to replace objects with objects that enhance the originals.
The ability to inject collaborating objects is often called IoC (inversion of control). Thus, Spring is an IoC container. If you follow the latest developer buzz then you've likely heard of IoC (Inversion of Control) containers and AOP (aspect-oriented programming). Like many developers, however, you may not see where these technologies fit into your development efforts. As the word inversion implies, IoC is like JNDI turned inside out. Instead of using a tangle of abstract factories, service locators, singletons, and straight construction, each object is constructed with its collaborating objects. Thus, the container manages the collaborators. (Collaborators are objects that an object needs to fullfill its role.)
The ability to dynamically add services to objects is called AOP. AOP allows developers to create non-domain concerns, called crosscutting concerns, and insert them in their application code. With AOP, common services like logging, persistence, transactions, and the like can be factored into aspects and applied to domain objects without complicating the object model of the domain objects.
Thus, Spring is an IoC/AOP container. There are many IoC containers. There are also many AOP frameworks. If Spring was only an IoC/AOP container, it would be worth your attention and interest since it seems to be the most mature. Spring is a lot more than an IoC/AOP container.
What makes Spring different than the other frameworks and containers, is Spring goes beyond just being an IoC container or an AOP framework. The other containers are academic interests, and some are quite good. They provide good support of IoC and AOP.
Spring goes one step further by eating its own dog food. It uses IoC and AOP to provide a comprehensive library for simplifying J2EE development. This comprehensive library is written with aspects, dependency injection and OOP best practices.
Spring makes J2EE development easier. It does this with a variety of mechanisms. One common mechanism is its use of templates. A template is a cross between a utility class and execution environment. Spring Templates are an embellishment and extention of the Template design pattern (GOF).
At first glance templates appear to be well written utility classes. However, templates provide a lot more than just utility functions. Templates provide and execution environment. When using a template you first endeavor to use one of its it utility method. If the template doesn't have a utility method you need, you implement a callback object. The callback object has a method that executes a method in the environment of the template. The template therefore takes care of things like exception handling and resource management in a consistent manner. This means your code base will not be littered with try/catch/finally blocks, and it is easier to ensure that resources and exception are handled correctly.
Spring promotes good programming practices. It does this by providing great examples how to use IoC and AOP in a consistent manner. It also does this by showing how to build things like templates to manage resources and exceptions in the consistent manner. It goes even further by building sets of frameworks on top of IoC, AOP and templates that are the embodiment of good OO programming.
The IoC capabilities allowing injection of dependent objects turns out to be a great mechanism for testing your code. It is easy now to inject mock objects (object for testing), and test your classes in an isolated manner. For example, you can test you business delegates without relying on the DAO (Data access objects) objects talking to the database. Essentially Spring took back development from the design pattern hacks deemed necessary to program J2EE. As Rod Johnson once put it: Spring puts the OO back in J2EE development.
Spring provides portability through abstraction of common services. For example, Spring provides a common interface object relational management (ORM) systems like Hibernate, JDO, Cayenne, Spring JDBC and iBatis. It provides a mechanism for building DAO objects that divorces the client code from the underlying implementation. it does this by providing a common set of exceptions like object not found exception, and making these exception runtime exceptions.
Spring provides a easy on-ramp for many industry-standard projects. And not just industry-standard projects but the de facto industry-standard projects. The projects that people actually use to get their daily work done. For example, Spring provides support for JDO, Hibernate, Quartz, Tapestry, JavaServer faces, and many more frameworks. Its been said that Spring simplifies J2EE development, and that is a primary focus of Spring. However,Spring provides utilities to work with all tiers of an n-tier application. For an MVC application, there are utilities for working with View technologies (Struts, Spring, Rich Client etc.), Model (EJB, AOP based transaction, AOP based security, etc.), etc. You can use Spring to build Swing and SWT applications.
If you have not looked into Spring yet, it is time.
------------------------------------------------
The above started as a reply to Cameron Purdy's prediction list, which I really liked. Then I got carried away and it became a full blown plug for Spring. (Darn Caffiene!)
What is Spring?
Spring is a popular AOP/IoC framework that was developed by Rod Johnson, Juergen Hoeller et al. Spring simplifies J2EE and Java development. Rod Johnson is the famed author who wrote Expert One-on-One J2EE Design and Development.
Spring makes J2EE development easier. Spring is a J2EE framework that simplifies commons tasks and encourages good design based on programming to interfaces. Springs makes your application easier to configure and reduces the need for many J2EE design patterns (quite a few J2EE design patterns are really glorified hacks that clutter your code base). Spring puts the OO design back into your J2EE application.
Published January 8, 2005 Reads 81,585
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Rick Hightower
Rick Hightower serves as chief technology officer for ArcMind Inc. He is coauthor of the popular book Java Tools for Extreme Programming, which covers applying XP to J2EE development, and also recently co-authored Professional Struts. He has been working with J2EE since the very early days and lately has been working mostly with Maven, Spring, JSF and Hibernate. Rick is a big JSF and Spring fan. Rick has taught several workshops and training courses involving the Spring framework as well as worked on several projects consulting, mentoring and developing with the Spring framework. He blogs at http://jroller.com/page/RickHigh.
![]() |
Rick Hightower 01/08/05 06:26:10 PM EST | |||
The article (like the last one I wrote) started out as being a blog entry (http://jroller.com/page/RickHigh/20050107#spring_plug). It is nice when the JDJ picks it up and gives it more exposure. The last blog entry turned article I wrote was read quite a bit according to the JDJ folks. I've written some follow up ideas at: |
||||
![]() |
Rick Hightower 01/08/05 05:53:57 PM EST | |||
I've used Spring on a half dozen different projects now (most if not all of them in production). The first time I used Spring I was amazed how much it helped to simplify the code base. Once you get rid of all of the service locators, and dynamic creation of implementations, and singletons, etc. then the code base gets a bit smaller. Also using the Spring templates really helps to keep things simple and yet manage resources well. I much prefer using Hibernate with Spring then without it. It really simplifies things. |
||||
![]() |
Agreed 01/08/05 05:20:08 AM EST | |||
Spring manages your mappings and helps maintain consistency across your data connections and helps you abstract your business logic, keeping it out of the actual pages. Best of all it also integrates with Struts. |
||||
![]() |
Spring has sprung 01/08/05 05:04:16 AM EST | |||
Wasn't it Purdy who said it's imposible to resist saying the word Spring. ("Yup, it's like trying not to think of pink elephants - impossible once you get that in your head. Spring, spring, spring, spring. La tee dah, spring spring spring.") What's in a name? |
||||
- IDEs Belong in the Cloud
- ActiveState Releases Komodo 7, "World's Fiercest IDE"
- eXo Platform 3.5 Now Available: First Cloud-Ready Enterprise Portal and User Experience Platform-as-a-Service (UXPaaS)
- Salesforce.com Announces the Availability of D&B Company Information in Data.com
- MercadoLibre Deploys Opscode Chef® to Automate its OpenStack Private Cloud
- Blog Summary for Week of February 6
- AppFog Enhances User Experience With Additional Add-On Partners Blitz.io and Iron.io
- CloudBees Reduces Cost to Run Java Applications by 62 Percent
- PatientsLikeMe Contributes Free Open-Source Parser to Blue Button Initiative
- BET and CENTRIC Pay Tribute to the Richness and Diversity of the African-American Experience With a Lineup of Dynamic Programming During Black History Month
- Brookfield Homes Calgary Partners with Interior Designer and TV Personality Jillian Harris
- McKinney and EvoApp Kick Off Social Bowl 2012
- IDEs Belong in the Cloud
- ActiveState Releases Komodo 7, "World's Fiercest IDE"
- eXo Platform 3.5 Now Available: First Cloud-Ready Enterprise Portal and User Experience Platform-as-a-Service (UXPaaS)
- Salesforce.com Announces the Availability of D&B Company Information in Data.com
- MercadoLibre Deploys Opscode Chef® to Automate its OpenStack Private Cloud
- Blog Summary for Week of February 6
- AppFog Enhances User Experience With Additional Add-On Partners Blitz.io and Iron.io
- CloudBees Reduces Cost to Run Java Applications by 62 Percent
- PatientsLikeMe Contributes Free Open-Source Parser to Blue Button Initiative
- BET and CENTRIC Pay Tribute to the Richness and Diversity of the African-American Experience With a Lineup of Dynamic Programming During Black History Month
- Brookfield Homes Calgary Partners with Interior Designer and TV Personality Jillian Harris
- McKinney and EvoApp Kick Off Social Bowl 2012
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- Ruby on Rails Won't Make It in 2007 and Forget About AJAX
- The Jury's Still Out On Ruby On Rails (RoR) and AJAX
- The Top 250 Players in the Cloud Computing Ecosystem
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- Ruby on Rails Creator Says: "Reduce the Risk, Hire Programmers From Open Source"
- Java Kicks Ruby on Rails in the Butt
- Can Ruby Live Without Rails?
- An Introduction to Ant
- Testing in Ruby on Rails
- 4th International Cloud Computing Conference & Expo Starts Today
- Cloud Expo 2011 East To Attract 10,000 Delegates and 200 Exhibitors


















