In this chapter, we are going to discuss the architecture of spring framework. Spring framework is an open source framework based on the Java platform. It provides an all-inclusive infrastructure support for the development of robust Java based applications in a very simple and rapid manner. It is also known to be a lightweight framework which is just around 2MB in size.
Spring is a framework that consists of multiple modules and it allows you the flexibility to choose a particular module that suits your need. E.g., if your application requires JDBC to be implemented then you can choose the Spring-JDBC module from the framework to implement it in your application. Spring framework is known to have around 20 such modules which can be applied to any Java based application. In the following diagram, we have listed the various frequently used modules which are available in the spring framework.
Data Access or Integration of Spring Framework
Spring framework has a Data Access or Integration layer which is composed of the JDBC module, ORM module, JMS module, OXM module, and the Transaction module. These modules are described below:
• The JDBC module: – This module of data access layer helps provide a JDBC (Java Database Connectivity) abstraction layer that eliminates the unnecessary need of monotonous JDBC related coding.
• The ORM module: – This module of data access layer helps provide the integration layers for standard object-relational mapping (ORM) APIs which includes JPA (Java Persistence API), JDO (Java Data Objects), Hibernate, and iBatis.
• The OXM module: – This module of data access layer helps provide an abstraction layer for standard Object-XML mapping implementations which includes JAXB, XMLBeans, Castor, JiBX and XStream.
• The JMS module: – JMS stands for Java Messaging Service. This module of data access layer provides support for the production and consumption of messages between modules or applications.
• The Transaction module: – This module of Data access or integration layer helps support the transaction management both programmatic and declarative for the classes which are implementing the special interfaces as well as all the POJOs (Plain Old Java Object) used in our JAVA application.
Web Layer of Spring Framework
Spring framework has a Web layer which is composed of the Web module, Web-MVC module, Web-Socket module, and Web-Portlet module. These modules are described below:
• The Web module: – This module of web layer helps provide a basic web-oriented integration features. It includes multipart file-upload functionality, the initialization of the IOC (Inversion of Control) container with the use of the servlet listeners, and a web-oriented application context.
• The Web-MVC module: – This module of web layer contains the spring framework’s MVC (Model, View and Controller) implementation for the Java based web applications.
• The Web-Socket module: – This module of web layer helps provide an extensive support for the Web Socket-based, two-way communication between the server and the client in any Java based web applications.
• The Web-Portlet module: – This module of web layer helps provide the spring framework’s MVC (Model, View and Controller) implementation which can be used in a portlet environment. Also, it can further help mirror the functionality of Web-Servlet module.
Core Container of Spring Framework
Spring framework has a Core Container which is composed of the Core module, Context module, Beans module, and Expression Language module. These modules are described below.
• The Core Module: – It provides the fundamental parts of the framework, which includes the popular IOC (Inversion of Control) and the Dependency Injection features of spring framework.
• The Bean Module: – It provides the Bean Factory, which is nothing but a stylish implementation of the factory pattern.
• The Context module: – This module helps build a base on top of the Core and Beans modules. Also, it serves as a medium to access any defined and configured object. It has an interface known as ApplicationContext that serves as a pivotal point of the Context module.
• The Expression Language Module: – The Expression language module of core container delivers the robust expression language that helps query the object graph and its manipulation at runtime.
Miscellaneous modules of Spring Framework
Apart from the above layers and modules, the spring framework has couple of other important modules such as AOP module, Aspects module, Instrumentation module, and Test module. These modules are described below.
• The AOP module: – AOP stands for Aspect oriented programming. This miscellaneous module helps provide an aspect-oriented programming (AOP) implementation which allows us to describe method-interceptors and pointcuts in order to decouple code so that the functionality could be separated.
• The Aspects module: – This miscellaneous module helps provide an integration with AspectJ. It is known to be a very powerful and mature AOP framework.
• The Instrumentation module: – This miscellaneous module helps provide a class instrumentation support as well as the class loader implementations which can be used in the various application servers.
• The Messaging module: – This miscellaneous module helps provide support for STOMP as the WebSocket sub-protocol to use in the Java based applications. Also, it is known to support an annotation programming model which helps in the routing and processing of the STOMP messages from the various WebSocket clients.
• The Test module: – This miscellaneous module helps provide an extensive support for the testing of the various spring components through leveraging the popular JUnit or TestNG frameworks.
In this chapter, we discussed the architecture of the spring framework. Here, we have covered the basic description of the various frequently used spring modules along with their appropriate implementation and use to build any robust Java based application in a very simple and rapid manner.