The Sample Applications

An area where many open source, and indeed commercial, products fail is in providing enough well-documented sample code to make it easy for people to get started. Thankfully, Spring comes with a complete set of nifty sample applications that demonstrate a wide selection of the features in Spring. A point to note is that the sample applications are treated as first-class citizens of the framework by the development team, and they are constantly being improved and worked on by the team. For this reason, you generally find that, after you get what you can from the test suite, the samples are a great place to get started when you are looking at new features.

The Petclinic Application

Petclinic is an interesting sample application that was built to showcase Spring's data access support. In it, you find a web-based application for querying and updating the database of a fictional veterinary office. The interesting thing about this application is that it comes with a selection of interchangeable DAO implementations that highlight how easy it is to decouple your application from the data access logic when you are using Spring.

The Hibernate DAO implementation really shows off Spring's Hibernate support by implementing each of the eight DAO methods with a single line. The JDBC implementation is equally as interesting. First, much of the JDBC logic is contained in an abstract base class.

This class provides hook methods for subclasses when you need to use provider-specific SQL features—in the Petclinic case, this happens with the auto generation of primary keys. Second, when you are looking at the base class, it is interesting to see how much of the repetitive error handling code that is prevalent when you are using JDBC is removed. Third, it is very interesting to see how data access is handled in a much more object-oriented way.

This project also contains a very solid example of how to build a web application using Spring's MVC support, so if you are planning to use Spring MVC for one of your own applications, make sure you take a look at this sample first.

We cover JDBC support in 18.

The jPetStore Application

The jPetStore is based on the jPetStore sample created by Clinton Begin for iBATIS. As far as sample applications go, this one is huge. It contains a full DAO layer, created using Spring and iBATIS, with implementations for Oracle, Microsoft SQL Server, MySQL, and PostgreSQL. The business tier is fully Spring managed and, coupled with the DAO layer, it presents a good example of Spring-managed transactions.

Also included with this application is a solid example of how to use both Spring MVC and Struts. This application also highlights how to use Spring remoting using JAXRPC.

Spring MVC is covered in Chapter 16.

The Tiles-Example Application

Tiles is one of our favorite open source tools because it reduces a lot of the drudge work when you are building user interfaces for the Web, and it really helps separate individual UI elements into reusable fragments. Because of this, the Tiles support in Spring is especially welcome, and this sample application makes getting started with Tiles in your own sample application easy.

We cover Tiles in detail in Chapter 18.

The ImageDB Application

This is one of our favorite sample applications because it shows off loads of useful Spring features. Specifically, you see how to load and store LOBs in a database, how to handle file uploads, and how to schedule jobs using the Quartz job scheduler. As if that weren't enough, you also see how to use Velocity as the view technology in the web tier.

We cover LOBs in Chapter 18.

The Countries Application

This is an intriguing example that demonstrates some of the more advanced features of Spring MVC. It looks at using HandlerInterceptors to provide common preprocessing for your Controllers as well as utilizing Excel and PDF output for the view technology. This example is quite small and is certainly worth a look if you are planning to use Excel or PDF within your application. We cover HandlerInterceptors in Chapter 18.



Pro Spring
Pro Spring
ISBN: 1590594614
EAN: 2147483647
Year: 2006
Pages: 189

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net