Skip to Main Content
Spring: A Developer's Notebook
book

Spring: A Developer's Notebook

by Bruce Tate, Justin Gehtland
April 2005
Intermediate to advanced content levelIntermediate to advanced
216 pages
4h 44m
English
O'Reilly Media, Inc.
Content preview from Spring: A Developer's Notebook

Injecting Dependencies with Spring

You're almost through with the setup for Spring. It's time to download it and put it into action. In this lab, you'll replace the RentABikeAssembler object with Spring.

When I started using Spring instead of J2EE, it changed my life. I got more productive. My code got easier for me to write, and easier for my customers to understand. Since it was simpler, it often executed faster. It was also infinitely easier to refactor. In fact, I wrote a book about the value of lightweight frameworks like Spring, called Better, Faster, Lighter Java (O'Reilly).

How do I do that?

You'll first have to download Spring. Go get it at http://www.springframework.org. That will point you to sourceforge, where you'll get the best version for your platform. We used Version 1.1. You will need to add a new folder to your project, war\WEB-INF\lib, and put the Spring libraries there (everything in the \dist folder of your Spring distribution).

Moving a well-designed plain-ordinary-Java-object (POJO) application to Spring is straightforward. It only takes three steps:

  • Refactor your code to take advantage of dependency injection. Model objects are beans, and services are aspects. Usually, you'll only have beans.

  • Remove the code that instantiates the objects and sets dependencies.

  • Build a configuration file describing your beans and aspects.

  • Access your code through Spring.

Since our individual parts are already built to take advantage of dependency injection, moving to Spring is an ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaBeans Unleashed

JavaBeans Unleashed

Dr. Donald Doherty, Rick Leinecker
Beginning Spring

Beginning Spring

Mert Caliskan, Kenan Sevindik, Rod Johnson, Jürgen Höller
Hibernate Search in Action

Hibernate Search in Action

Emmanuel Bernard, John Griffin

Publisher Resources

ISBN: 0596009100Supplemental ContentErrata Page