Spring: A Developer's Notebook and over 1.5 million other books are available for Amazon Kindle . Learn more


or
Sign in to turn on 1-Click ordering.
More Buying Choices
Have one to sell? Sell yours here
Sorry, this item is not available in
Image not available for
Colour:
Image not available

 
Start reading Spring: A Developer's Notebook on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Spring: A Developer's Notebook [Paperback]

Bruce A. Tate , Justin Gehtland
2.5 out of 5 stars  See all reviews (4 customer reviews)
RRP: £22.99
Price: £19.06 & this item Delivered FREE in the UK with Super Saver Delivery. See details and conditions
You Save: £3.93 (17%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Only 1 left in stock (more on the way).
Dispatched from and sold by Amazon. Gift-wrap available.
Want it Friday, 21 June? Choose Express delivery at checkout. Details

Formats

Amazon Price New from Used from
Kindle Edition £16.34  
Paperback £19.06  
Amazon.co.uk Trade-In Store
Did you know you can trade in your old books for an Amazon.co.uk Gift Card to spend on the things you want? Visit the Books Trade-In Store for more details. Special Offer until June 30, 2013: Receive an additional £5 promotional Gift Certificate, when you trade-in at least £10 worth of books. Learn more.

Book Description

17 April 2005 0596009100 978-0596009106 1

Since development first began on Spring in 2003, there's been a constant buzz about it in Java development publications and corporate IT departments. The reason is clear: Spring is a lightweight Java framework in a world of complex heavyweight architectures that take forever to implement. Spring is like a breath of fresh air to overworked developers.

In Spring, you can make an object secure, remote, or transactional, with a couple of lines of configuration instead of embedded code. The resulting application is simple and clean. In Spring, you can work less and go home early, because you can strip away a whole lot of the redundant code that you tend to see in most J2EE applications. You won't be nearly as burdened with meaningless detail. In Spring, you can change your mind without the consequences bleeding through your entire application. You'll adapt much more quickly than you ever could before.

Spring: A Developer's Notebook offers a quick dive into the new Spring framework, designed to let you get hands-on as quickly as you like. If you don't want to bother with a lot of theory, this book is definitely for you. You'll work through one example after another. Along the way, you'll discover the energy and promise of the Spring framework.

This practical guide features ten code-intensive labs that'll rapidly get you up to speed. You'll learn how to do the following, and more:

  • install the Spring Framework
  • set up the development environment
  • use Spring with other open source Java tools such as Tomcat, Struts, and Hibernate
  • master AOP and transactions
  • utilize ORM solutions
As with all titles in the Developer's Notebook series, this no-nonsense book skips all the boring prose and cuts right to the chase. It's an approach that forces you to get your hands dirty by working through one instructional example after another-examples that speak to you instead of at you.

Customers Who Viewed This Item Also Viewed


Product details

  • Paperback: 216 pages
  • Publisher: O'Reilly Media; 1 edition (17 April 2005)
  • Language: English
  • ISBN-10: 0596009100
  • ISBN-13: 978-0596009106
  • Product Dimensions: 15.3 x 1.3 x 22.9 cm
  • Average Customer Review: 2.5 out of 5 stars  See all reviews (4 customer reviews)
  • Amazon Bestsellers Rank: 964,283 in Books (See Top 100 in Books)
  • See Complete Table of Contents

More About the Authors

Discover books, learn about writers, and more.

Product Description

About the Author

Bruce A. Tate is a kayaker, mountain biker, and father of two. In his spare time, he is an independent consultant in Austin, Texas. In 2001, he founded J2Life, LLC, a consulting firm that specializes in Java persistence frameworks and lightweight development methods. His customers have included FedEx, Great West Life, TheServerSide, and BEA. He speaks at conferences and Java user's groups around the nation. Before striking out on his own, Bruce spent 13 years at IBM working on database technologies, object-oriented infrastructure, and Java. He was recruited away from IBM to help start the client services practice in an Austin startup called Pervado Systems. He later served a brief stint as CTO of IronGrid, which built nimble Java performance tools. Bruce is the author of four books, including the bestselling Bitter Java, and the recently released Better, Faster, Lighter Java, from O'Reilly. First rule of kayak: When in doubt, paddle like Hell.

Working as a professional programmer, instructor, speaker and pundit since 1992, Justin Gehtland has developed real-world applications using VB, COM, .NET, Java, Perl and a slew of obscure technologies since relegated to the trash heap of technical history. His focus has historically been on "connected" applications, which of course has led him down the COM+, ASP/ASP.NET and JSP roads.

Justin is the co-author of Effective Visual Basic (Addison Wesley, 2001) and Windows Forms Programming in Visual Basic .NET (Addison Wesley, 2003). He is currently the regular Agility columnist on The Server Side .NET, and works as a consultant through his company Relevance, LLC in addition to teaching for DevelopMentor.

Excerpt. © Reprinted by permission. All rights reserved.

CHAPTER 6 Services and AOP

Most kayakers that I know are demented and proud of it. We tend to look for those places on a river that are dangerous enough to scare but tame enough to play. While I was learning to surf hydraulics on Barton Creek at high water, I slipped into a hydraulic to play, but couldn’t get out. I flipped, upstream, and the hydraulic quickly flipped me 360 degrees, so that I was upright again. I frantically surfed a little while longer, then flipped again, and then all of my control deserted me. The hydraulic then took over, and spun me around like a window shade. When my friends laughed and grabbed their cameras instead of their safety ropes, I bailed, coughing and gagging my way to the bank to nurse my battered ego. I mumbled something about my boat being the source of the problem. Predictably, one of my friends got into my boat, and then toyed with my nemesis, the killer hydraulic, for a while. To make things worse, he then threw his paddle onto the bank, and played some more. He!
said, "Bruce, it’s not the boat. It’s how you use it." I’m still fuming today.

I’m starting to recognize that the same is true of many Java services. It’s not the service; it’s how you apply it. You can get a whole lot more leverage out of certain services like transactions, security, and logging by packaging them and using them in a way that simplifies them and eliminates duplication in the rest of the code. Spring uses aspect-oriented programming (AOP) to manage these services, called crosscutting concerns. In this chapter, you’ll learn to build and configure such a service using an interceptor.

Building a Service

The core functions of your application are roughly complete, but it’s going to be hard to trace what changes a user made, and when. In this example, you’ll build an audit trail that records a log record whenever someone takes an action that changes the database. Rather than add the same code in many different places, you’ll build a simple Spring service to do the job. You’ll focus on the Hibernate implementation that you built earlier.

Object-oriented languages handle some problems pretty well, but they don’t handle crosscutting concerns, common in enterprise developments, very well. Figure 6-1 shows a method with some common enterprise services that crosscut many methods in DAO and façade layers.

To handle crosscutting concerns, you might decide to use a container. Most containers accept only components that match their specification, and provide services to components once they’re in the container. Heavyweight container architectures, like EJB 1.x and 2.x, handle crosscutting concerns, but they force you to write code that depends on your given container. You can’t take the code out of the container and expect it to run, and since the container takes too long to start, the result is difficult to test.

Lightweight containers that use AOP technologies accept components too, but the component is a simple POJO. You can then use AOP to attach services to the POJO. We’ll get into how this works later in the chapter, but for now, think of this feature as the ability to add declarative services to POJO. In Spring, you implement declarative services with configuration rather than code, so you can change services on the fly through changes in the context.

How do I do that?

The interceptor strategy uses three objects: the target (our façade), a proxy object that Spring creates for you, and an interceptor, which you’ll build. Essentially, the proxy imitates the target—wherever you would use an instance of the target object, Spring will use the proxy instead. The proxy will pass all calls to the object through a series of interceptors that you’ll configure in the context. Depending on the type of interceptors, the call might pass through the interceptor before reaching the target, on the way back from the target, or both.

You’ve got to do three things:

1. Create your service, which we’ll call an interceptor. Another word for interceptors is advice.
2. Configure the beans: the interceptor and the target object.
3. Configure the proxy—identify the proxy, the target object, and the methods that will use our service.

To build advice, you’ll simply implement an interface. Think of advice as something that will happen at some event in a program’s execution. Spring has four types of advice:

Before advice
Spring fires this type of advice before it invokes a method that you specify, called the target method. This type of advice implements the MethodBeforeAdvice interface.

After Returning advice
Spring fires this type of advice after returning from your target method. After Returning advice implements the AfterReturningAdvice interface.

Throws advice
Spring fires this type of advice when your target method throws an exception. This type of advice implements the ThrowsAdvice interface.

Around advice
Spring fires this type of advice before a method, and allows you to choose whether to invoke the target method. After the target method returns, you can add additional code. This is also called an interceptor.

In general, you should use the simplest type of advice that will solve your problem. For this example, you’ll use before advice, and you’ll build on the Hibernate interface. The interceptor will implement the MethodBeforeAdvice interface. It will do the logging. Don’t worry about how it gets invoked just yet. Example 6-1 gives the advice.

Example 6-1. LoggingBefore.java

public class LoggingBefore implements MethodBeforeAdvice {

private SessionFactory factory;

public SessionFactory getFactory( ) {
return factory;
}

public void setFactory(SessionFactory factory) {
this.factory = factory;
}

public void before(Method method, Object[] objects, Object o)
throws Throwable {

Session s = null;
LogEvent le = new LogEvent(method.getName(), new Date( ));
try {
s = factory.openSession( );
s.save(le);
} catch (Exception ex) {
//log the exception
} finally {
s.close( );
}
}
}


Inside This Book (Learn More)
Browse Sample Pages
Front Cover | Copyright | Table of Contents | Excerpt | Index | Back Cover
Search inside this book:

What Other Items Do Customers Buy After Viewing This Item?


Customer Reviews

Most Helpful Customer Reviews
12 of 12 people found the following review helpful
3.0 out of 5 stars Good intentions, poor execution 1 Jun 2005
By A Customer
Format:Paperback
I had used the Hibernate - Dev Notebook some weeks ago and found it a thoroughly excellent book. Held your hand tightly as you learnt the concepts and almost 100% accurate in terms of instructions / code samples. However, the same cannot be said for this one.

There are fairly substantial gaps in the book which are simply glossed over and leaves you confused and wondering what to do next.
There are pieces of configuration which are simply left out from the configuration and when you run the code, nothing works. After much digging in other Spring Ref manuals, managed to figure it out.

Having said all that, increased my Spring knowledge and teaches you not only the concept but how to apply it in code. So, achieves it's goal albeit painfully!

Comment | 
Was this review helpful to you?
1 of 1 people found the following review helpful
4.0 out of 5 stars Not perfect but damn useful 23 May 2008
Format:Paperback
Personally I found this book has a very useful role. Due to its scope and flexibility Spring can sometimes be pretty intimidating. I have been repeatedly reading through 'Spring in Action' and 'Professional Java Development with Spring'. They are both great books but contain so many abstract concepts that it can be hard to take in.

This book is useful because it takes a concrete (and realistic) example, and explains why you need to be using the various parts of the Spring framework. After reading the other books several times each and still feeling confused, I found that this book had me understanding everything within minutes. It is useful for getting you up and running quickly but certainly doesn't cover everything - you still need the other books.
Comment | 
Was this review helpful to you?
1 of 1 people found the following review helpful
1.0 out of 5 stars A book full of CRAP 26 Mar 2008
Format:Paperback
This is complete waste of time. Instead of acting as a quick intro to Spring technology, this book wastes a lot of time trying to figure out how to run examples and even the code in the book and downloaded from website doesn't work.

Can I get my money and time I spent back? Also there should be an option for -ve stars.
Comment | 
Was this review helpful to you?
2.0 out of 5 stars Still marred by incomplete coding examples 13 Sep 2008
Format:Paperback
After buying this book I ran into horror stories on the web about how the coding examples were completely broken. The good news is that most of the errata do now (2008) seem to have been applied. The bad news is that there are still gaps and inconsistencies. If you buy this book make sure to check all the errata sheets at the book's web-site before trying to get anything to work. Also download the source code, but be aware that it will require some work to get going, especially the build.xml files, which still have numerous dependencies to the authors' personal directory layout.

Also note that the book is peppered with irrelevant references to Bruce Tate's favoured pastimes of kayaking and mountain-biking. These add nothing whatever to the book and it would be better without them.
Comment | 
Was this review helpful to you?
Would you like to see more reviews about this item?
Were these reviews helpful?   Let us know
Search Customer Reviews
Only search this product's reviews

Customer Discussions

This product's forum
Discussion Replies Latest Post
No discussions yet

Ask questions, Share opinions, Gain insight
Start a new discussion
Topic:
First post:
Prompts for sign-in
 

Search Customer Discussions
Search all Amazon discussions
   


Listmania!


Look for similar items by category


Feedback


Amazon.co.uk Privacy Statement Amazon.co.uk Delivery Information Amazon.co.uk Returns & Exchanges