Understanding Spring Packaging

When you obtain a distribution of Spring, you may be surprised to find that rather than distributing a single JAR file with all the code in it, the Spring team opted to create a single JAR that contains a full distribution and eight separate JARs that contain individual Spring components. In future releases, it is likely that the number of component JARs will increase, thus enabling you to be more selective of the features you include in your code.

The Full Distribution

The spring.jar file available in every release contains almost the full distribution of the Spring framework classes. We say almost because it doesn't actually contain any of the mock classes that are distributed with Spring as testing aids. This is a good decision by the Spring team, because you almost never have to distribute mock classes in a release of your application; instead, you use them in the development environment to aid your testing process. Aside from this one omission, the spring.jar file contains every class in the main Spring source tree.

The Component Distributions

In addition to the spring.jar file, Spring comes with another eight JAR files as mentioned earlier; one contains the mock classes and the other seven contain individual components of the Spring framework. Table 2-1 lists these JAR files along with a description of their corresponding components.

Table 2-1: Spring Component Distributions

JAR File

Description

spring-aop.jar

This JAR contains all the classes you need to use Spring's AOP features within your application. You also need to include this JAR in your application if you plan to use other features in Spring that use AOP, such as declarative transaction management.

spring-context.jar

This package contains classes that provide many extensions to the Spring core. You will find that all classes need to use Spring's ApplicationContext feature (covered in Chapter 5), along with classes for EJB, JNDI, and mail integration. Also contained in this package are the Spring remoting classes, classes for integration with templating engines such as Velocity and FreeMarker and the base validation classes. It is worth bearing in mind that many of the classes contained in this package are really out of place, and features such as remoting and EJB support would be better packaged into additional JAR files.

spring-core.jar

This is one JAR file that you need for every application. In this JAR file, you will find all the classes for accessing configuration files, creating and managing beans, and performing DI. If all you want for your application is basic DI support, then all you need is this JAR file. Also, in this JAR, you will find a selection of extremely useful utility classes that are used throughout the Spring codebase and that you can also use in your own application.

spring-dao.jar

This JAR contains all the base classes for Spring DAO support, including all classes for accessing data using JDBC and Spring's transaction abstraction layer. In order to use the declarative transaction support, you need to include spring- aop.jar in your application as well.

spring-mock.jar

As we mentioned earlier, Spring provides a set of mock classes to aid in testing your applications. Many of these mock classes are used within the Spring test suite, so they are well tested and make testing your applications much simpler. Certainly we have found great use for the mock HttpServletRequest and HttpServletResponse classes in unit tests for our web applications.

spring-orm.jar

This JAR extends Spring's standard DAO feature set with support for Hibernate, iBATIS and JDO. Many of the classes in this JAR depend on classes contained in spring-dao.jar, so you definitely need to include that in your application as well. In the future, individual ORM tools may be packaged separately, because you do not need to include classes for Hibernate and JDO when your application is using iBATIS.

spring-web.jar

This JAR file contains the core classes for using Spring in your web applications, including classes for loading an ApplicationContext feature automatically, Struts integration classes, file upload support classes, and a bunch of useful classes for performing repetitive tasks such as parsing int values from the query string.

spring-webmvc.jar

This JAR contains all the classes for Spring's own MVC framework. If you are using a separate MVC framework for your application, then you won't need any of the classes from this JAR file. Spring MVC is covered in more detail in 18.

Choosing a Distribution Option

Choosing which of these distribution options to use is actually quite simple. If you are building a web application and you will be using Spring throughout it, then you may as well use the spring.jar file and save yourself the hassle of having to maintain the different files. Likewise, if all you want is a simple DI container for your application, then you should be okay with just spring-core.jar. If the size of your release is critical, then you will almost certainly want to pick the JAR files containing just the features that you need.

Bear in mind that the component distributions are not really that granular; you will almost certainly end up including whole sets of classes in your application that you do not need. You may be able to make your application slightly smaller, but the big space savings come from knowing exactly which of Spring's dependencies you need to include in your application and discarding the rest.



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

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