EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial Spring Modules
Secondary Sidebar
Spring Tutorial
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

Spring Modules

Spring Modules

Introduction to Spring Modules

Spring Modules 2

Spring Framework Modules can be highly classified into, Core Container acts as the main/base module of the Spring which contains the below sub-modules such as Beans, Core, Context & Expression Language. Web Layer is responsible for creating Web Applications. Sub Modules include Web, Servlet & Portlet. Data Access/Integration Layer is responsible for interacting with the database &  Integration with ORM frameworks. Sub Modules include JDBC, ORM, OXM, JMS & Transactions. Test Layer has its own Testing framework which has good binding & support for testing the application using Junit or Mockito or TestNG. Miscellaneous Layer includes AOP (Aspect Oriented Programming) & Instrumentation. In this topic, we are going to learn about Spring Modules.

Spring Modules Explanation

Core Container – Beans & Core

Core Container, the brain of the Spring Module is responsible for implementing the Inversion of Control (IoC) or Dependency Injection (DI). This helps in achieving the loose coupling between classes.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

In a conventional way, developers will have control over the code in creating the objects & injecting the dependencies. Here the Spring frameworks take the control of doing the above-mentioned activities, that’s why the term is coined as “Inversion of Control”  – i.e., the control is inverted!

Dependency Injection is a pattern that adheres/implemented Inversion of Control for resolving the dependencies.

Objects, which acts as the backbone of your application & are managed (i.e., instantiation, configuration & assembling) by the IoC Container are called Beans.

Until here, you should be clear about IoC concepts. But how do the beans get instantiated? It is taken care of by means of Autowiring. Spring framework makes use of Autowiring concepts for instantiating the beans into the required class at the time of booting (starting) up the application.

Spring Context

Spring Context is a sub-module of Core Container which has been built on the base of Spring Core & Beans. It is mainly responsible for instantiating & configuring the beans by scanning the configurations from Spring annotations or XML files.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,754 ratings)

Additionally, it provides support for Internationalization(i18N), resource loading & event-propagation.

Internationalization (i18N)

Spring Internationalization helps in designing the Web Application to be accessed/adapted to various languages across the world. This will help the end-users to access/walk through the application or website in their own language.

i18N can be achieved by configuring the messages/sentences in message-{language}.properties file.

For example, for English – the words & sentences can be maintained in message-en.properties whereas for Hungarian, it can be maintained in message-hgr.properties file.

Spring Expression Language (SpEL)

SpEL is a Spring-based Expression Language for evaluating the expression such as Mathematical Operations, Logical & Relation Operations, Conditional Operations & RegEx.

Real-time example:

Spring Modules output 1

Output

Value: Hello Muneer Ahmed J

Result: 50

Data Access/Integration Layer

Here are the layers mention below

JDBC Layer

JDBC Layer provides a wrapper or an abstraction over the conventional JDBC.

In JDBC Connection, developers need to write boilerplate coding for Creating, Opening & Closing of DB Connection, Executing Queries etc., But with the help Spring JDBC Template, the Spring Framework takes cares of the above-mentioned tasks.

Additionally, JDBC Templates are thread-safe, i.e., with a single instance of JDBC Template, we can make use of it in different DAO classes.

The conventional way of establishing a JDBC Connection

Spring Modules output 2

Using Spring JDBC Template

Spring Modules output 3

Spring Modules output 4

DaoImpl class which makes use of JDBC Template for executing the queries. Here you can notice that boilerplate codes i.e.,  explicitly registering the drivers, opening/closing the DB Connection have not been used.

ORM Layer

Spring ORM (Object Relational Mapping) Layer provides support for integrating with various ORM frameworks such as Hibernate, JPA, etc., Spring doesn’t provide any changes in the ORM layer, but it provides some additional features for handling the ORM layer efficiently.

To make things clear, JPA is only a specification. To make use of it, you will need an implementation for it. Spring Data JPA is one such implementation.

A real-time example of Spring Data JPA

output 5

output 6

output 7

EmployeeRepository class acts as the Repository layer has been extended to JpaRepository. Spring Data JPA Layer provides readymade methods such as save, findById, deletebyId, etc.,

As you can see in EmployeeService class, we have not written any query for saving the Object, instead, we are making of in-built ‘save’ method for saving the employee basic details object into the database.

OXM Layer

Spring OXM Layer provides a wrapper or an abstraction layer for supporting Java Object to XML Document mappings & vice versa (i.e., XML Marshalling & Unmarshalling) with various implementation frameworks such as JAXB, XStream, Castor, etc.,

Real-time Use Case:

In the SOAP Web Service Environment, we need to accept the requests and return the response to the clients in XML format. In this case, developers need to convert the XML into Java Objects for processing (Marshalling) and after processing, the Java Object needs to converted back into XML Response & send it back to the Clients.

Real-time example using JAXB

 output 8

output 9

Output Response:

 output 10

Spring Web/MVC Layer

Spring MVC refers to Model, View & Controller.

The architecture of Spring MVC

The architecture of Spring MVC

Steps for Spring MVC Model

  • Once an HTTP request is made from the Client layer, Dispatcher Servlet will provide the request endpoint to the Handler Mapping to route it to the required controller.
  • From Controller, it is routed to the Service Layer to implement any business logic & then to the DAO Layer (in case of any DB transactions).
  • Once done, data will be set into Model Objects & then will be routed to the View Layer.
  • Here, Dispatcher Servlet will provide the details to the View Resolver in finding the corresponding view.
  • Once done, the HTTP response along with Model data objects will be routed to the View (HTML file) which will be rendered in the browser.

To help the Dispatcher Servlet to handle the HTTP request, mapping of the URL will be maintained in the web.xml file (i.e., Deployment Descriptor).

Spring Test Module

Spring Test Module has a testing framework that provides support for testing the spring components independently using Junit or TestNG.

Since the Spring framework uses Dependency Injection for loose coupling, it helps the developer to perform the Unit Testing easily with the help of the Junit Framework.

In a traditional way, Integration testing can be performed once after the application is deployed. But Spring provides an easy way to Mock or Stub the objects & perform the Integration Testing.

Conclusion

From this article, we have done deep dive of Spring Modules with real-time scenarios & code snippets. In a nutshell, Spring Modules helps the developers to handle the application more efficiently with fewer efforts & coding.

Recommended Articles

This is a guide to Spring Modules. Here we discuss the Explanation of Spring Modules along with the real-time scenarios & code snippets.  You may also have a look at the following articles to learn more –

  1. Spring AOP
  2. Spring Boot Versions
  3. Spring Boot Feature
  4. Spring Boot Application
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more