Spring Architecture

The Spring framework has a layered architecture made up of seven well-defined modules.

Allows you to choose only those modules that suit your application needs and leave out those not required for your application.

The seven modules in the Spring framework are:

  • Spring core module
  • Spring application context module
  • Spring Data Access Object (DAO) module
  • Spring ORM module
  • Spring AOP module
  • Spring Web context module
  • Spring Web MVC module

All the seven modules are built on top of the core container. The core container is responsible for creating, configuring, and managing the JavaBeans.

Spring Architecture

Test

This layer provides support of testing with JUnit and TestNG.

Spring Core Container

Core and Beans

It has fundamental functionality of the Spring framework.

Contains the most important component of the Spring framework, the bean factory container.

The bean factory container forms the basis for implementing DI within the application.

To implement the core module within your Web application, you need to use the org.springframework.core package.

Core and beans provide IOC and Dependency Injection features.

Context

It is a means to access objects in a framework-style manner that is similar to a JNDI registry. The Context module inherits its features from the Beans module and adds support for internationalization (using, for example, resource bundles), event propagation, resource loading, and the transparent creation of contexts by, for example, a Servlet container. The Context module also supports Java EE features such as EJB, JMX, and basic remoting.

Expression Language

It is an extension to the EL defined in JSP. It provides support to setting and getting property values, method invocation, accessing collections and indexers, named variables, logical and arithmetic operators, retrieval of objects by name etc.

AOP, Aspects and Instrumentation

These modules support aspect oriented programming implementation where you can use Advices, Pointcuts etc. to decouple the code.

The aspects module provides support to integration with AspectJ.

The instrumentation module provides support to class instrumentation and classloader implementations.

Messaging

Spring Framework 4 includes a spring-messaging module with key abstractions from the Spring Integration project such as Message, MessageChannel, MessageHandler, and others to serve as a foundation for messaging-based applications. The module also includes a set of annotations for mapping messages to methods, similar to the Spring MVC annotation based programming model.

Data Access / Integration

Aims to standardize data access work through technologies, such as Hibernate, JDO, or JDBC.

Enables you to write simple database code without worrying about tasks, such as opening and closing the database connection.

DAO provides an exception hierarchy for:

  • Managing database connections.
  • Handling exceptions.
  • Handling complicated error messages thrown by different database servers.

To implement the DAO module in your Web application, you need to use the org.springframework.dao package.

The ORM module

Enables developers to integrate the Spring framework with several other ORM tools, such as Hibernate, iBatis, and JDO, as required for the application.

Is built upon the DAO module to provide an easy way to build DAOs for the ORM tool, as required by the application.

Is implemented by using the org.springframework.orm package.

Web

The Web layer consists of the spring-web, spring-webmvc, spring-websocket, and spring-webmvc-portlet modules.

The spring-web module provides basic web-oriented integration features such as multipart file upload functionality and the initialization of the IoC container using Servlet listeners and a web-oriented application context. It also contains the web-related parts of Spring's remoting support.

The spring-webmvc module (also known as the Web-Servlet module) contains Spring's model-view-controller (MVC) implementation for web applications. Spring's MVC framework provides a clean separation between domain model code and web forms and integrates with all of the other features of the Spring Framework.

The spring-webmvc-portlet module (also known as the Web-Portlet module) provides the MVC implementation to be used in a Portlet environment and mirrors the functionality of the spring-webmvc module.