Unit 5 Spring
Unit 5 Spring
Unit 5: Spring
• We can create web-based applications easily due to its vast library and tools.
• It provides support to many other frameworks such as Hibernate, Tapestry, EJB, JSF, Struts,
etc, so it is also called a framework of frameworks.
• It is full of features and provides various other sub-projects such as Spring Security, Spring
Boot, Spring MVC, Spring Cloud, Spring Data, etc that help to build applications accordingly.
• With the help of Spring Boot we can create applications in a DevOps and cloud-friendly way.
Introduction to Spring
• The core and heart of Spring is an IOC container that manages bean objects and allows
dependency injection.
• Spring is lightweight when it comes to size and transparency. The basic version of Spring
framework is around 2MB.
• The core features of the Spring Framework can be used in developing any Java application,
but there are extensions for building web applications on top of the Java EE platform.
• Spring framework targets to make J2EE development easier to use and promotes good
programming practices by enabling a POJO-based programming model.
Spring Framework
• The Spring framework is modular and consists of several modules that provide different
functionalities to help build enterprise applications.
• The Spring framework comprises of many modules such as core, beans, context, expression
language, AOP, Aspects, Instrumentation, JDBC, ORM, OXM, JMS, Transaction, Web, Servlet,
Struts etc.
• The modules can be broadly categorized into four main areas: Core Container, Data
Access/Integration, Web, and Miscellaneous.
• The Spring framework is a powerful and popular open-source Java framework that provides a
comprehensive programming and configuration model for building enterprise applications.
• Its architecture is designed around the principles of modularity, separation of concerns, and
flexibility, providing developers with a powerful set of tools to build robust, scalable, and
maintainable enterprise applications.
Spring Framework
• The Core Container
• Spring Core: Spring IoC (Inversion of Control) is the heart of the Spring Framework,
responsible for creating and managing instances of JavaBeans. It uses dependency injection
to wire the beans together.
• Spring Beans: This module provides the BeanFactory, which is the basic building block of
the IoC container, and the BeanWrapper, which is responsible for managing the lifecycle of
a bean. The Bean Factory is the core interface for accessing the IoC container. It provides
methods for retrieving beans.
• Spring Context: The Context module uses the base provided by the Core and Beans
modules. It has access rights for any objects that define and configure. In Context module,
the major point is ApplicationContext interface.
• Spring Expression Language (SpEL): This module provides a powerful expression language
for querying and manipulating objects during runtime. SpEL supports a wide range of
features, including property access, method invocation, conditionals, loops, and type
conversion.
• Data Access/Integration
• Spring JDBC: Spring JDBC provides support for transaction management, allowing
developers to manage database transactions declaratively using Spring’s transaction
management.
• Spring ORM: This module provides integration with Object-Relational Mapping (ORM)
frameworks, such as Hibernate and JPA.
• Spring Data: This module provides a consistent and easy-to-use programming model for
working with data access technologies, including databases, NoSQL, and cloud-based data
services.
• Spring Transaction: The Spring Transaction Management module is for coordinating the
Java objects transaction. It is also used to unify several transaction management APIs.
• The Web area provides support for building web applications. It includes the following
modules:
• Spring MVC: This module provides a Model-View-Controller (MVC) framework for building web
applications. Spring MVC provides a range of features, including support for handling HTTP
requests and responses, form handling, data binding, validation, and more. It also provides
support for different view technologies, such as JSP (JavaServer Pages), Thymeleaf, and
Velocity, allowing developers to choose the view technology that best suits their needs.
• Spring WebFlux: This module provides a reactive programming model for building web
applications that require high concurrency and scalability. It also provides a range of features,
including support for reactive data access, reactive stream processing, and reactive HTTP
clients.
• Spring Web Services: This module provides support for building SOAP-based and RESTful web
services. Spring Web Services provides support for generating WSDL (Web Services Description
Language) from Java classes, and for generating Java classes from WSDL.
• Miscellaneous
• Spring Security: This module provides authentication and authorization features for Spring
applications. Spring Security provides a range of authorization mechanisms, such as role-
based access control and expression-based access control.
• Spring Integration: This module provides support for building message-driven and event-
driven architectures. Spring Integration provides a range of integration patterns, such as
messaging, routing, and transformation. It also provides support for integrating with
different protocols, such as FTP, HTTP, and TCP.
• Spring Batch: This module provides support for batch processing and integration with
enterprise systems. Spring Batch provides a range of tools and utilities for building and
managing batch processing applications, such as support for testing and debugging batch
jobs, logging and monitoring, and integration with other Spring modules, such as Spring
Data and Spring Integration.
• Spring Cloud: This module provides support for building cloud-native applications using
Spring technologies. Spring Cloud provides a range of features for building cloud-native
applications, such as service discovery, configuration management, and load balancing
Application of Spring
• Modular
• Spring is set up in a modular approach. Even if there are a lot of packages and classes, you only need to worry about the
ones you need and ignore the rest.
• Integration with existing frameworks
• Spring does not reinvent the wheel; rather, it makes extensive use of existing technologies such as numerous ORM
frameworks, logging frameworks, JEE, Quartz, and JDK timers, and other view technologies.
• Web MVC
• Spring’s web framework is a well-designed web MVC framework that is an excellent alternative to web frameworks like
Struts and other over-engineered or less popular web frameworks.
• Central Exception Handling
• Spring provides a handy API for converting technology-specific exceptions (such as those raised by JDBC, Hibernate, or
JDO) into consistent, unchecked exceptions.
• Lightweight
• IoC containers are typically lightweight, especially when compared to EJB containers, for example. This is useful for
creating and distributing programmes on systems with limited memory and CPU resources.
Introduction to Spring MVC
• Spring MVC is a Java-based framework that is mostly used for developing web
applications.
• It follows the MVC (Model-View-Controller) Design Pattern.
• This design pattern specifies that an application consists of a data model,
presentation information, and control information.
• This framework is developed around a DispatcherServlet which dispatches
requests to handlers.
• A Spring MVC provides an elegant solution to use MVC in spring framework by
the help of DispatcherServlet.
• Here, DispatcherServlet is a class that receives the incoming request and maps
it to the right resource such as controllers, models, and views.
• In the current industry, many of them are using Spring Boot Microservices, but
there are many projects still running in Spring MVC.
Spring MVC Framework
Spring Web Model-View-Controller
•Model - A model contains the data of the application. A data can be a single object or a
collection of objects.
•Controller - A controller contains the business logic of an application. Here, the @Controller
annotation is used to mark the class as the controller.
•View - A view represents the provided information in a particular format. Generally, JSP+JSTL
is used to create a view page. Although spring also supports other view technologies such as
Apache Velocity, Thymeleaf and FreeMarker.
•Front Controller - In Spring Web MVC, the DispatcherServlet class works as the front
controller. It is responsible to manage the flow of the Spring MVC application.
Spring DispatcherServlet
• Dispatcher Servlet is the front controller that manages the entire HTTP request and response
handling process.
• It is quite simple, as the name suggests, when any web requests are made, the requests will
come first to the front Controller which is nothing but the Dispatcher Servlet.
• The Front Controller stands first that is why it’s name is like this.
• After the requests comes into this, the dispatcher servlet accepts the requests and decides
which controller will be suitable to handle these requests.
CSE Department
7 0 7 0 2 5 4 4 8 6
www.cgu-odisha.edu.in