0% found this document useful (0 votes)
2 views5 pages

CH5 SpringFramework

The Spring Framework, developed by Rod Johnson in 2003, is a lightweight framework for JavaEE applications that supports various frameworks and provides several modules like IOC, AOP, and MVC. It utilizes design patterns such as Inversion of Control and Dependency Injection to create loosely coupled code that is easier to test and maintain. Spring MVC, a part of the framework, follows the Model-View-Controller design pattern, facilitating the development of web applications with clear separation of roles and rapid development capabilities.

Uploaded by

shankarranbavle6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

CH5 SpringFramework

The Spring Framework, developed by Rod Johnson in 2003, is a lightweight framework for JavaEE applications that supports various frameworks and provides several modules like IOC, AOP, and MVC. It utilizes design patterns such as Inversion of Control and Dependency Injection to create loosely coupled code that is easier to test and maintain. Spring MVC, a part of the framework, follows the Model-View-Controller design pattern, facilitating the development of web applications with clear separation of roles and rapid development capabilities.

Uploaded by

shankarranbavle6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter 5: SpringFramework

It was developed by Rod Johnson in 2003. Spring framework makes the easy development of
JavaEEapplications.
Spring Framework
 Spring is a lightweight framework.
 It can be thought of as a framework of frameworks because it provides support to various
frameworks such as Struts, Hibernate, Tapestry, EJB, JSF, etc.
 The framework can be defined as a structure where we find solution of the various
technical problems.
 The Spring framework comprises several modules such as IOC, AOP, DAO, Context,
ORM, WEB MVC etc.
Inversion Of Control (IOC) and Dependency Injection
 These are the design patterns that are used to remove dependency from the programming
code.
 They make the code easier to test and maintain.
1.
class Employee{
Address address;
Employee(){
address=new Address();
}
}
 In such case, there is dependency between the Employee and Address (tight coupling). In
the Inversion of Control scenario, we do this something like this:
class Employee{
Address address;
Employee(Address address){
this.address=address;
}
}
 Thus, IOC makes the code loosely coupled. In such case, there is no need to modify the
code if our logic is moved to new environment.
 In Spring framework, IOC container is responsible to inject the dependency. We provide
metadata to the IOC container either by XML file or annotation.
Advantages of Dependency Injection
o makes the code loosely coupled so easy to maintain
o makes the code easy to test

Advantages of Spring Framework


There are many advantages of Spring Framework.
 Predefined Templates:
Spring framework provides templates for JDBC, Hibernate, JPA etc. technologies. So
there is no need to write too much code. It hides the basic steps of these technologies.
EX: In JdbcTemplate, you don't need to write the code for exception handling, creating
connection, creating statement, committing transaction, closing connection etc. You need
to write the code of executing query only. Thus, it save a lot of JDBC code.
 Loose Coupling
The Spring applications are loosely coupled because of dependency injection.
 Easy to test
The Dependency Injection makes easier to test the application. The EJB or Struts
application require server to run the application but Spring framework doesn't require
server.
 Lightweight
Spring framework is lightweight because of its POJO(Plain Old Java Object)
implementation. The Spring Framework doesn't force the programmer to inherit any class
or implement any interface. That is why it is said non-invasive.
 Fast Development
The Dependency Injection feature of Spring Framework and it support to various
frameworks makes the easy development of JavaEE application.
 Powerful abstraction
It provides powerful abstraction to JavaEE specifications such as JMS, JDBC, JPA and
JTA.
 Declarative support
It provides declarative support for caching, validation, transactions and formatting.

Spring Modules
 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.
 These modules are grouped into Test, Core Container, AOP, Aspects, Instrumentation,
Data Access / Integration, Web (MVC / Remoting) as displayed in the following
diagram.
.
 Test
o This layer provides support of testing with JUnit and TestNG.
 Spring Core Container
o The Spring Core container contains core, beans, context and expression language
(EL) modules.
 Core and Beans
o These modules provide IOC and Dependency Injection features.
 Context
o This module supports internationalization (I18N), EJB, JMS, Basic Remoting.
 Expression Language
o It is an extension to the EL defined in JSP. It provides support to setting and
getting property values, method invocation, accessing collections and indexers,
named variables, logical and arithmetic operators, retrieval of objects by name
etc.
 AOP, Aspects and Instrumentation
o These modules support aspect oriented programming implementation where you
can use Advices, Pointcuts etc. to decouple the code.
o The aspects module provides support to integration with AspectJ.
o The instrumentation module provides support to class instrumentation and
classloader implementations.
 Data Access / Integration
o This group comprises of JDBC, ORM, OXM, JMS and Transaction modules.
These modules basically provide support to interact with the database.
 Web
o This group comprises of Web, Web-Servlet, Web-Struts and Web-Portlet. These
modules provide support to create web application.
Spring MVC
 A Spring MVC is a Java framework which is used to build web applications. It follows
the Model-View-Controller design pattern. It implements all the basic features of a core
spring framework like Inversion of Control, Dependency Injection.
 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.

o Model - A model contains the data of the application. A data can be a single object or a
collection of objects.
o Controller - A controller contains the business logic of an application. Here, the
@Controller annotation is used to mark the class as the controller.
o 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.
o 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 .
Understanding the flow of Spring Web MVC
o As displayed in the figure, all the incoming request is intercepted by the
DispatcherServlet that works as the front controller.
o The DispatcherServlet gets an entry of handler mapping from the XML file and forwards
the request to the controller.
o The controller returns an object of ModelAndView.
o The DispatcherServlet checks the entry of view resolver in the XML file and invokes the
specified view component.
Advantages of Spring MVC Framework
The advantages of Spring MVC Framework:-
o Separate roles - The Spring MVC separates each role, where the model object,
controller, command object, view resolver, DispatcherServlet, validator, etc. can be
fulfilled by a specialized object.
o Light-weight - It uses light-weight servlet container to develop and deploy your
application.
o Powerful Configuration - It provides a robust configuration for both framework and
application classes that includes easy referencing across contexts, such as from web
controllers to business objects and validators.
o Rapid development - The Spring MVC facilitates fast and parallel development.
o Reusable business code - Instead of creating new objects, it allows us to use the existing
business objects.
o Easy to test - In Spring, generally we create JavaBeans classes that enable you to inject
test data using the setter methods.
o Flexible Mapping - It provides the specific annotations that easily redirect the page.

---------xxxxxxxxxx-----------

You might also like