Spring Framework is one of the most commonly used Java EE open source framework, initially written by Rod Johnson and was released under the Apache 2.0 license in June 2003. The Spring Framework provides a comprehensive and infrastructural support providing focus on building application-level business logic and reduces the ties on specific deployment environments.
The tutorial is designed on the Spring Version Spring 5 for the student and Java developers or anyone who wants to learn spring framework for implementing the learned skills to enhance their career path.
Table of Contents
What is Spring Framework ?
Spring framework is a modular architecture consisting of several modules (grouped as Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation, Messaging, and Test) which allows developers to build enterprise web applications with the ease. Developers can select the modules required for building the components of web applications without having to bring in all the modules and thus makes it lightweight and flexible as developers are using only the required set of modules and not the complete bundle . The below given is the Spring Architecture Diagram highlighting the main modules it provides. Let’s discuss about the architecture components to understand how they can be used in the application development.
Core Container in Spring
The Spring Core Container consists of spring-core, spring-beans, spring-context, spring-context-support, and spring-expression (expression language) modules
- The spring-core and spring-beans
- The spring-beans module provides BeanFactory, which inherits the implementation of the factory pattern.
- The spring-context module provides the mechanism to access objects in a framework-style manner, similar to a JNDI registry with the base foundation of spring-core and spring-beans modules. The Context module inherits spring-beans module to provide support for internationalization (resource bundles), event propagation, resource loading, and the transparent creation of contexts (Servlet Container) and also supports Java EE features such as EJB, JMX, and basic remoting. The ApplicationContext interface is the focal point of the Context module.
- The spring-expression (SpEL) module provides a powerful expression language for querying and manipulating an object graph at runtime.
Data Access / Integration in Spring
The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS and Transaction modules. Let’s discuss about these components to understand how they can be used in the application development.
- The spring-jdbc (JDBC) module provides a JDBC-abstraction layer that removes the need for tedious JDBC related coding and parsing of vendor specific error codes.
- The spring-orm (ORM)module provides integration layers for popular object-relational mapping APIs, including Hibernate, JPA, JPA, Top Link, JDO and iBatis.
- The spring-oxm (OXM) module provides an abstraction layer that supports Object/XML mapping implementations for JAXB, Castor, XML Beans, JiBX and XStream
- The spring-jms (Java Messaging Service -JMS) module contains features for producing and consuming messages.
- The spring-tx (Transaction) module supports programmatic and declarative transaction management for classes that implement special interfaces and for all your POJOs
Web Layer in Spring
The Web layer consists of the Web (spring-web), Web-MVC(spring-webmvc), Web-Socket (spring-websocket) and Web Portlet (Web-Portlet) modules. Let’s discuss about these components to understand how they can be used in the application development.
- The Web module provides basic web-oriented integration features such as HTTP Client for remoting support, multipart file-upload functionality and the initialization of the IoC container using servlet listeners and a web-oriented application context.
- The Web-MVC module contains Spring’s Model-View-Controller (MVC) and REST Services implementation for web applications.
- The Web-Socket module provides support for WebSocket-based, two-way communication between the client and the server in web applications.
- The Web-Portlet module provides the MVC implementation to be used in a portlet environment and mirrors the functionality of Web-Servlet module
AOP , Aspects, Instrumentation in Spring
spring-aopmodule provides an aspect-oriented programming implementation allows developers to define method interceptors and pointcuts to cleanly decouple code that implements functionality that should be separated.
- The spring-aspects (Aspects) module provides integration with AspectJ, which is again a powerful and mature AOP framework
- The spring-instrument (Instrumentation) module provides class instrumentation support and class loader implementations to be used in certain application servers. The
spring-instrument-tomcatmodule contains Spring’s instrumentation agent for Tomcat
The spring-messaging (Messaging) module provides key abstractions such as
MessageHandler and provides support for STOMP as the Web Socket sub-protocol to
use in applications. It also provides the set of annotations for
mapping messages to methods, similar to the Spring MVC annotation based
Test module in Spring
- The spring-test (Test) module supports the Unit testing and Integration Testing of Spring components with JUnit or