Introduction to Spring Modules

Spring Modules

There are more than 20 spring modules available as Core Module, Data Access Module, Web Module, AOP Module, Instrumentation Module and Testing Module.

You don’t need to include all of them in order to use spring in your project. You can include the module of your choice. Suppose you don’t need web functionality in your project then you don’t need to use spring’s Web Module or if you are not planning to use AOP features then you don’t need to include it as part of your project.


spring modules
spring modules

Now let’s discuss them one by one and understand what they are.


Core Modules or Core Container

Core modules is the basic building block of the spring IoC and Dependency injection. Spring core modules consist of spring-core, spring-bean, spring-context, spring-context-support and spring-expression. Spring-core and spring-beans modules provide the support for IoC and Dependency Injection features.

Spring-context is build on the base provided by Core and Bean modules. ApplicationContext is the main interface provided by the context modules which provides some additional application specific features over BeanFactory of core module.

Spring-expression, expression language is mainly used to query and manipulate the group or individual object. Spring supports this feature with the spring-expression module.  


AOP Module

Spring-aop stands for Aspects Oriented Programming, which allows you to define method interceptors and pointcuts to cleanly decouple code of your application.

To understand this concept let’s take an example of logging features in our application which is very basic and required functionality. Now in order to log messages or exception, we usually create object or our logger and then use it in every area of our class methods. We repeat logging code in each and every time to log before or after code executes.

Now let’s say you don’t need to write logging functionality in your class. You can completely remove it from your code. You just write your business logic. Now your class will perform only and only business logics. Your class is now not taking the responsibility of logging the messages and some interceptor things.

This can be done by AOP, you can define interceptors using AOP module which will execute before or after the method.


Instrumentation

The spring-instrument module provides class instrumentation support and class loader implementations to be used in certain application servers. The spring-instrument-tomcat module contains Spring’s instrumentation agent for Tomcat.


Messaging Module

Spring Framework 4 includes spring-messaging module as spring integration project such as Message, MessageChannel and MessageHandler. It includes set of annotations fro mapping messages to methods.


Data Access and Integration

Data Access modules is a module which provides an architecture to communicate with the database in framework style manner.

It is a channel between application and the database. It consists of different modules such as JDBC, ORM, OXM, JMS and Transaction Modules. Spring-jdbc module provides support for JDBC operations. It provides us an abstraction layer, so that we don’t need to write tedious JDBC coding and parsing database specific error codes.
With the help of JDBC template, it is easy to manage database results and queries.

Spring-tx module supports programmatic and declarative transaction management for classes that implement special interfaces and for all your POJOs.

Spring-orm provides integration support for the popular Object Relational Mapping (ORM) APIs, like JPA, JDO and Hibernate. With the help of spring-orm modules, you will be able to easily integrate those ORM tools in your project.

Spring-oxm module provides layer for Object and XML mapping implementation like JAXB, Castor, XMLBeans, JiBX and XStream. It is now easy to transform your object to XML and vice versa.

Spring-jms module provides support for producing and consuming messages.


Web Module

Web Module is a specific module for developing web applications. If you want to develop fully MVC enabled enterprise level application, then you need to include web module in your project. Web module mainly consists of spring-web, spring-webmvc, spring-websocket and spring-webmvc-portlet.

Spring-web provides basic web-oriented functionality such as multipart file upload, initialization of the IoC container using Servlet listener and web oriented application context WebApplicationContext.

Spring-webmvc module container MVC (Model View Controller) functionality and REST web services implementation support.

Spring-webmvc-portlet module is specific to portlet environment and mirrors the functionality of the servlet-based spring-webmvc module.


Testing

The spring-test module supports the unit testing and integration testing of Spring components with JUnit or TestNG. It provides consistent loading of Spring ApplicationContexts and caching of those contexts. It also provides mock objects that you can use to test your code in isolation.

Related Post

One thought on “Introduction to Spring Modules”

Leave a Reply

Your email address will not be published. Required fields are marked *