Spring Modules

The Spring Framework is composed of several well-defined modules built on top of the core container. This modularity makes it possible to use as much or as little of the Spring Framework as is needed in a particular application.

The core container

At the very base of figure 1.1, you’ll find Spring’s core container. Spring’s core container provides the fundamental functionality of the Spring Framework. This module contains the BeanFactory, which is the fundamental Spring container and the basis on which Spring’s DI is based. We’ll be discussing the core module (the center of any Spring application) throughout this blog.

Application context module

Spring’s application context builds on the core container. The core module’s BeanFactory makes Spring a container, but the context module is what makes it a framework. This module extends the concept of BeanFactory, adding support for internationalization (I18N) messages, application lifecycle events, and validation. In addition, this module supplies many enterprise services such as email, JNDI access, EJB integration, remoting, and scheduling. Also included is support for integration with templating frameworks such as Velocity and FreeMarker.

Spring’s AOP module

Spring provides rich support for aspect-oriented programming in its AOP module. This module serves as the basis for developing your own aspects for your Springenabled application. Like DI, AOP supports loose coupling of application objects. With AOP, however, applicationwide concerns (such as transactions and security) are decoupled from the objects to which they are applied. Spring’s AOP module offers several approaches to building aspects, including building aspects based on AOP Alliance interfaces (http://aopalliance.sf.net) and support for AspectJ.

JDBC abstraction and the DAO module

Working with JDBC often results in a lot of boilerplate code that gets a connection, creates a statement, processes a result set, and then closes the connection. Spring’s JDBC and Data Access Objects (DAO) module abstracts away the boilerplate code so that you can keep your database code clean and simple, and prevents problems that result from a failure to close database resources. This module also builds a layer of meaningful exceptions on top of the error messages given by several database servers. No more trying to decipher cryptic and proprietary SQL error messages! In addition, this module uses Spring’s AOP module to provide transaction management services for objects in a Spring application. We’ll see how Spring’s template-based JDBC abstraction can greatly simplify JDBC code when we look at Spring data access.

Object-relational mapping (ORM) integration module

For those who prefer using an object-relational mapping (ORM) tool over straight JDBC, Spring provides the ORM module. Spring’s ORM support builds on the DAO support, providing a convenient way to build DAOs for several ORM solutions. Spring doesn’t attempt to implement its own ORM solution, but does provide hooks into several popular ORM frameworks, including Hibernate, Java Persistence API, Java Data Objects, and iBATIS SQL Maps. Spring’s transaction management supports each of these ORM frameworks as well as JDBC.

In addition to Spring’s template-based JDBC abstraction, we’ll look at how Spring provides a similar abstraction for ORM and persistence frameworks.

Java Management Extensions (JMX)

Exposing the inner workings of a Java application for management is a critical part of making an application production ready. Spring’s JMX module makes it easy to expose your application’s beans as JMX MBeans. This makes it possible to monitor and reconfigure a running application.

Java EE Connector API (JCA)

The enterprise application landscape is littered with a mishmash of applications running on an array of disparate servers and platforms. Integrating these applications can be tricky. The Java EE Connection API (better known as JCA) provides a standard way of integrating Java applications with a variety of enterprise information systems, including mainframes and databases.

In many ways, JCA is much like JDBC, except where JDBC is focused on database access, JCA is a more general-purpose API connecting to legacy systems. Spring’s support for JCA is similar to its JDBC support, abstracting away JCA’s boilerplate code into templates.

The Spring MVC framework

The Model/View/Controller (MVC) paradigm is a commonly accepted approach to building web applications such that the user interface is separate from the application logic. Java has no shortage of MVC frameworks, with Apache Struts, JSF, WebWork, and Tapestry among the most popular MVC choices. Even though Spring integrates with several popular MVC frameworks, it also comes with its own very capable MVC framework that promotes Spring’s loosely coupled techniques in the web layer of an application.

Spring Portlet MVC

Many web applications are page based—that is, each request to the application results in a completely new page being displayed. Each page typically presents a specific piece of information or prompts the user with a specific form. In contrast, portlet-based applications aggregate several bits of functionality on a single web page. This provides a view into several applications at once. If you’re building portlet-enabled applications, you’ll certainly want to look at Spring’s Portlet MVC framework. Spring Portlet MVC builds on Spring MVC to provide a set of controllers that support Java’s portlet API.

Spring’s web module

Spring MVC and Spring Portlet MVC require special consideration when loading the Spring application context. Therefore, Spring’s web module provides special support classes for Spring MVC and Spring Portlet MVC. The web module also contains support for several web-oriented tasks, such as multipart file uploads and programmatic binding of request parameters to your business objects. It also contains integration support with Apache Struts and Java- Server Faces (JSF).

Remoting

Not all applications work alone. Oftentimes, it’s necessary for an application to leverage the functionality of another application to get its work done. When the other application is accessed over the network, some form of remoting is used for communication. Spring’s remoting support enables you to expose the functionality of your Java objects as remote objects. Or if you need to access objects remotely, the remoting module also makes simple work of wiring remote objects into your application as if they were local POJOs. Several remoting options are available, including Remote Method Invocation (RMI), Hessian, Burlap, JAXRPC, and Spring’s own HTTP Invoker.

Java Message Service (JMS)

The downside to remoting is that it depends on network reliability and that both ends of the communication be available. Message-oriented communication, on the other hand, is more reliable and guarantees delivery of messages, even if the network and endpoints are unreliable. Spring’s Java Message Service (JMS) module helps you send messages to JMS message queues and topics. At the same time, this module also helps you create A Spring jump start 11 message-driven POJOs that are capable of consuming asynchronous messages.