Spring framework overview

Spring is one of the most popular open source framework in Java to develop enterprise level applications.

Spring is also a very light weight to start with, as the basic version of the spring framework is just around 2MB. Spring could be easily integrated with the application using dependency and build tools, such as, Maven, Gradle, Ivy etc.

Spring framework is very modular in nature, and has about 20 modules which can be used to make a robust application.

Here are few benefits of Spring framework:

  • Spring is a very light weight, its development is easy with POJO (Plain Old Java Objects).
  • Spring believes in loose coupling and it achieves it through dependency injection (DI) and interface based programming.
  • Spring used Aspect Oriented Programming (AOP), which again provides modularity to the application.
  • Spring is shipped with some key technologies such as ORM framework, logging framework, J2EE etc.
  • Spring has a module for web, Spring MVC, and it is just superb!
  • Spring does not require the need to build a singleton or  factory classes.
  • Spring support lightweight IoC containers, which are lighter as compared to Enterprise Java Beans (EJB) containers, thus, making Spring an ideal choice for developing applications with limited memory and CPU.
  • Spring provides consistent transaction management interface, which works as fine as in local transaction as it will in global transaction.
  • Spring applications are easily testable. POJO’s in Spring application gives good reason for a testable code.
  • Spring framework could easily be used from a GUI to a Web Application to a Standalone applications and if still in use, then for Applets as well!

 

Spring Architecture

spring-overview

Let us go through the architecture:

  • Spring core container : This is the soul of the framework. This container provides implementation for IoC supporting DI. This container provides mechanism for managing and configuring Java objects using call backs. The core container is responsible for managing the life cycle of objects, i.e; creating objects, calling initialization methods, writing the objects together to configure them.
    • The Core module is what provides IoC and DI features to the rest of the framework.
    • Bean module, is the sophisticated implementation of factory pattern by providing BeanFactory.
    • The Context module stands on the solid base provided by Core and Bean modules. This module is a medium to access any objects defined and configured. The ApplicationContext is the central point of the context module.
    • SpEl, provides a powerful Expression Language for the purpose of querying and manipulating object graph at runtime. The language provides mechanism for getting and settings property values, accessing content of the arrays, property assignment, method invocation, retrieval of objects by name etc. from Springs IoC container. It also provides common list aggregations.
  • Aspect Oriented Programming : This module provides mechanism for AOP Alliance-complaint programming implementation. To decouple code by using pointcuts and method interceptors that implements functionality and which should be separated is taken care by AOP. Spring also support AspectJ by using spring-aspects module.
  • Instrumentation : This module is used to provide class instrumentation support and classloader implementations for some application servers, ex; Spring-instrument-tomcat is used as Spring instrumentation agent in Tomcat.
  • Messaging : This feature was added in Spring version 4.0. Using spring-messaging the framework adds support for a simple text-based protocol for working with message-oriented middleware (MOM), called Simple (or Streaming) Text Oriented Message Protocol (STOMP)STOMP is the WebSocket module sub-protocol to use in applications along with an annotation programming model for routing and processing STOMP messages from WebSocket clients.
  • Data Access / Integration : This layer contains modules for data related operations.
    • JDBC : This module provides abstraction layer to remove the need for using tedious JDBC coding and parsing of database-vendor specific error codes.
    • Transactions : This module provides robust transaction support for the framework using spring-tx module. Spring provides consistent transaction management system using different API’s, ex; Java Transaction API (JTA), JDBC, Hibernate, Java Persistence API (JPA) and Java Data Objects (JDO).
    • ORM : Object relational mapping, is a programming technique that lets you query and manipulate data from a database using object-oriented paradigm. The popular API’s which the Spring framework supports are JPA, JDO and Hibernate.
    • OXM :  Object/XML Mapping is the act of converting an XML document to and from an object. This process is also called XML Marshalling or XML Serialization. This layer provides abstraction for OXM by supporting implementations such as JAXB, Castor, XMLBeans, JiBX and XStream.
    • JMS : Java Messaging Service (JMS) contains the features for producing and consuming messages. Since, Spring framework 4.1 the module has been moved to spring-messaing module.
  • Web : As the name suggests, this layer helps developers develop web applications.
    • spring-web: This module provides basic web oriented features, ex: IoC container initialization using servlet listerners and a application context for web, multipart file upload etc.
    • spring-mvc: This is the module which supports Model View Controller (MVC) and REST web services for web applications.
    • Portlet: This module supports MVC implementation in Portlet environment and is a replica of Springs spring-mvc module.
    • WebSocket: This module is responsible for providing implementation for Web sockets in Spring for web applications.
  • Test : This layer is responsible for the support to unit testing and integration testing of Spring components using JUnit or TestNG. This layer also provides mock objects that can be used to test the code in isolation.