KEMBAR78
Spring framework Introduction | PPTX
SESSION – 1 & 2
By→ Anuj Kumar Singh
1. A framework, or software framework, is a platform for developing
software applications. It provides a foundation on which software
developers can build programs for a specific purpose.
2. A need of framework is a re-usable design platform for software
systems, which provides support for code libraries.
3. There are framework for Java, PHP, Ruby and many others.
4. All software frameworks are built with the idea of re-usability of the
code and provide tools that help the programmers develop and
mount together the different components of the software project.
What is a Framework?
These are the frames for constructing any building or house, for constructing
any building or house a frame is made first and then only the work based on
that frame is started, so this is what a framework is.
Example: 1
Suppose you have to make a tea on daily basis with several ingredients
like sugar, tea leaves , other spices , etc. In doing so on daily basis most
of the time you will find it is really difficult to put all ingredients in right
ratio all time you can forget sometimes, you have to open several boxes
one by one, one morning you come up with idea of mixing all ingredients
in one jar in one ratio, such that every spoon will serve the right ratio mix
to the tea. ( Off course milk and water remain aside :) )
Example: 2
This jar is your framework. When we want to do lots of things on regular
basis it just consumes time and a framework will not only save time it
will also provide right components in your applications fast and easy.
Popular Frameworks
CSS Bootstrap for front-end, Java Spring and PHP Laravel for back-end
Rod Johnson Ben Alex Thomas Risberg
Rod Johnson  Roderick "Rod" Johnson is an Australian computer specialist who created the
Spring Framework.
Ben Alex  Ben Alex develop and sends ACEGI Security code to Rod Johnson.
Thomas Risberg  Thomas Risberg is responsible for enhancements to the JDBC framework
portion.
Spring Framework  Developers
What is Spring Framework ?
1. Spring framework was developed by Rod Johnson and was first
released in 2003 in Spring Organization now Pivotal.
2. Spring Framework is replacement / alternative of EJB’s (Enterprise
Java Beans) because of heavy weight of EJB’s
3. Earlier name of Spring Framework was Interface21 later changed to
Spring based on Spring season.
4. Spring Framework is a open source Java Platform that provides
support for developing robust (Strong Memory Management and No
Pointers) Java application very easily and rapidly.
EJB is a specification, while Spring is an implementation. Spring itself was
developed as an alternative to EJB 2.0 primarily. There was EJB 3.0
which was developed to rectify the drawbacks in EJB 2.0. So if we
primarily compare EJB 3.0 with Spring on various parameters, it would be
as follows.
EJB’s Spring
The Applications developed under EJB
framework were heavy-weight because it uses
the libraries of the Application server + JDK
(Java Development Kit). EJB container is a part
of application server like JBoss which is heavy-
weight.
Spring is Light-weight because it uses only
it’s Jar file and JDK. It’s is not dependent on
application server that’s makes it much
lighter as compared to the EJB framework.
The Applications developed under EJB were
tightly-coupled i.e. if the other class object is
created in the dependent class then there exist
a Tight-coupling. Any changes in the class
object leads to the change in the Dependent
class.
Spring is loosely-coupled because if we
want any changes in the object of class then
we just need to configure the spring
configuration xml file (Spring manages
objects). We need not to make any changes
in the Dependent Class.
Why Spring Framework not EJB’s
Point of Comparison EJB’s Spring
Transaction Management Only JTA (Java Transaction API)
is supported.
Spring supports a wider
range, including JTA, JDBC,
Hibernate.
Persistence In EJB it is tightly integrated with
JPA (Java Persistence API)
Spring supports a wider range
that includes JPA, Hibernate,
JDBC
State Management Stateful Session Beans in EJB Spring it is indirectly
dependent on container
session management.
AOP EJB provide limited support Spring is more robust support
via AspectJ.
Security EJB has support security through
JAAS (Java Authentication and
Authorization Service)
Spring can go beyond JAAS,
through ACEGI (security 2.0)
Why Spring Framework?
1. Spring is the most popular application development framework for
enterprise. Millions of developers around the world use Spring
Framework to create high performing, easily testable, and reusable
code.
2. Spring is lightweight when it comes to size and transparency. The
basic version of Spring framework is around 2MB.
3. Spring framework is the extensions for building web applications on
top of the Java EE platform.
4. Spring framework targets to make J2EE development easier to use
and promotes good programming practices by enabling a POJO-
based programming model.
Versions of Spring Framework
Version Year Features
0.9 2002
1.0 2003 AOP , Application context concept, DAO support, JDBC
abstraction, Hibernate support, etc
2.0 2006 IoC container, Easier XML configuration, Easier AOP XML
configuration, Tag library for Spring MVC, etc
3.0 2009 Spring Expression Language, IoC enhancements,
Object to XML mapping, @MVC additions, etc
4.0 2013 Core Container Improvements, General Web
Improvements, WebSocket and STOMP Messaging
Testing Improvements, etc
5.0 2017 JDK baseline update, Core container updates. Functional
programming with Kotlin. Testing improvements.
Spring Architecture (Very loosely coupled, components widely reusable)
and separately packaged.
1. Spring allows to decouple software layers by injecting a
component’s dependencies at runtime rather than having them
declared at compile time.
2. Spring provides integration for J2EE services such as EJB, JDBC.
It also integrates several popular ORM toolkits such as Hibernate
and JDO and assorted other services as well.
3. Spring is built on the principle of unchecked exception handling.
This also reduces code dependencies between layers. Spring
provides a granular exception hierarchy for data access operations
and maps JDBC, EJB, and ORM exceptions to Spring exceptions
so that applications can get better information about the error
condition.
Core Container
1. The Core module provides the fundamental parts of the framework,
including the IoC and Dependency Injection features.
2. The Bean module provides BeanFactory, which is a sophisticated
implementation of the factory pattern.
3. The Context module builds on the solid base provided by the Core
and Beans modules and it is a medium to access any objects
defined and configured. The ApplicationContext interface is the
focal point of the Context module.
4. The SpEL module provides a powerful expression language for
querying and manipulating an object graph at runtime.
Data Access/Integration
1. The JDBC module provides a JDBC-abstraction layer that removes
the need for tedious JDBC related coding.
2. The ORM module provides integration layers for popular object-
relational mapping APIs, including JDO, Hibernate.
3. The OXM module provides an abstraction layer that supports
Object/XML mapping implementations for XMLBeans.
4. The Java Messaging Service JMS module contains features for
producing and consuming messages.
5. The Transaction module supports programmatic and declarative
transaction management for classes that implement special
interfaces and for all your POJOs.
Web
1. The Web module provides basic web-oriented integration features
such as multipart file-upload functionality and the initialization of the
IoC container using servlet listeners and a web-oriented application
context.
2. The Web-MVC module contains Spring's Model-View-Controller
(MVC) implementation for web applications.
3. The Web-Socket module provides support for WebSocket-based,
two-way communication between the client and the server in web
applications.
4. The Web-Portlet module provides the MVC implementation to be
used in a portlet environment and mirrors the functionality of Web-
Servlet module.
Miscellaneous
1. The AOP module provides an aspect-oriented programming
implementation allowing you to define method-interceptors and
pointcuts to cleanly decouple code.
2. The Aspects module provides integration with AspectJ, which is
again a powerful and mature AOP framework.
3. The Instrumentation module provides class instrumentation support
and class loader implementations to be used in certain application
servers.
4. The Messaging module provides support for STOMP as the
WebSocket sub-protocol to use in applications.
5. The Test module supports the testing of Spring components with
frameworks.
What is MVC(Model View Controller)
1. It follow the software Architectural pattern.
2. One of the most frequently used pattern.
3. Separate application functionality.
Model: (All Business Logic ) Pogo, Business Object, DAO classes
1. Data related logic
2. Interaction with database (INSERT,DELETE,UPDATE,SELECT)
3. Communication with Controller.
4. Can sometimes update the View
View: (Presentation View)  jsp, html, css
1. What the end user see.
2. Usually consist of HTML/CSS
3. Communicate with Controller.
4. Template Engine for variables
Controller: (request , response) Servlet
1. Receives request from View (url form)
2. Process the request.
3. Gets data from Model.
4. Response with data to the View.
Flow Control in Spring MVC
1. We have Controller which handle the request coming from client, but
the controller don’t get request directly, first the request is passed
(filtered) from the Dispatcher-Servlet.
2. The Dispatcher-Servlet is also known as Front-Controller provided
by Spring Framework and it is present inside the web.xml file.
3. The Dispatcher-Servlet or Front-Controller get to know about what
client has requested for, with the help of Configuration File
(configSpring.xml).
4. The Configuration File has all the mapping information for Controller
through Front-Controller.
5. And based on that mapping the response is generated by the
Controller and transferred to the Client.
Advantages of Spring MVC
1. 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.
2. Light-weight - It uses light-weight servlet container to develop and
deploy your application.
3. 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.
4. Rapid development - The Spring MVC facilitates fast and parallel
development.
5. Reusable business code - Instead of creating new objects, it allows
us to use the existing business objects.
6. Easy to test - In Spring, generally we create JavaBeans classes
that enable you to inject test data using the setter methods.
7. Flexible Mapping - It provides the specific annotations that easily
redirect the page.
IDE’S (Integrated Development Environment’s) Available
1. Eclipse
Step 1: Click on File
Step 2: Select New
Step 3: Click on Other…
1. Eclipse
2. NetBeans
3. IntelliJ IDEA
etc
Project Setup in Eclipse and NetBeans
Step 4: Click on Maven Project
Step 5: Click on Next
Step 6: Browse and Set the default location for saving files
Step 7: Click on Next
Step 8: Select the webapp Group Id and Artifact Id
Step 9: Click on Next
Step 10: Give Artifact Name
Step 11: Click on Finish
2. NetBeans
Step 1: Click on New Project
Step 2: Select Java Web
Step 3: Select Web Application
Step 4: Click on Next
Step 5: Give Project Name
Step 6: Click on Next
Step 7: Select the Server
Step 8: Click on Next
Step 9: Select the Spring Web MVC
Step 10: Click on Finish
Example
1. POJO (PLAIN OLD JAVA OBJECT)
2. Test Class
3. XML Bean File
Spring framework  Introduction

Spring framework Introduction

  • 1.
    SESSION – 1& 2 By→ Anuj Kumar Singh
  • 2.
    1. A framework,or software framework, is a platform for developing software applications. It provides a foundation on which software developers can build programs for a specific purpose. 2. A need of framework is a re-usable design platform for software systems, which provides support for code libraries. 3. There are framework for Java, PHP, Ruby and many others. 4. All software frameworks are built with the idea of re-usability of the code and provide tools that help the programmers develop and mount together the different components of the software project. What is a Framework?
  • 3.
    These are theframes for constructing any building or house, for constructing any building or house a frame is made first and then only the work based on that frame is started, so this is what a framework is. Example: 1
  • 4.
    Suppose you haveto make a tea on daily basis with several ingredients like sugar, tea leaves , other spices , etc. In doing so on daily basis most of the time you will find it is really difficult to put all ingredients in right ratio all time you can forget sometimes, you have to open several boxes one by one, one morning you come up with idea of mixing all ingredients in one jar in one ratio, such that every spoon will serve the right ratio mix to the tea. ( Off course milk and water remain aside :) ) Example: 2
  • 5.
    This jar isyour framework. When we want to do lots of things on regular basis it just consumes time and a framework will not only save time it will also provide right components in your applications fast and easy. Popular Frameworks CSS Bootstrap for front-end, Java Spring and PHP Laravel for back-end
  • 6.
    Rod Johnson BenAlex Thomas Risberg Rod Johnson  Roderick "Rod" Johnson is an Australian computer specialist who created the Spring Framework. Ben Alex  Ben Alex develop and sends ACEGI Security code to Rod Johnson. Thomas Risberg  Thomas Risberg is responsible for enhancements to the JDBC framework portion. Spring Framework  Developers
  • 7.
    What is SpringFramework ? 1. Spring framework was developed by Rod Johnson and was first released in 2003 in Spring Organization now Pivotal. 2. Spring Framework is replacement / alternative of EJB’s (Enterprise Java Beans) because of heavy weight of EJB’s 3. Earlier name of Spring Framework was Interface21 later changed to Spring based on Spring season. 4. Spring Framework is a open source Java Platform that provides support for developing robust (Strong Memory Management and No Pointers) Java application very easily and rapidly.
  • 8.
    EJB is aspecification, while Spring is an implementation. Spring itself was developed as an alternative to EJB 2.0 primarily. There was EJB 3.0 which was developed to rectify the drawbacks in EJB 2.0. So if we primarily compare EJB 3.0 with Spring on various parameters, it would be as follows.
  • 9.
    EJB’s Spring The Applicationsdeveloped under EJB framework were heavy-weight because it uses the libraries of the Application server + JDK (Java Development Kit). EJB container is a part of application server like JBoss which is heavy- weight. Spring is Light-weight because it uses only it’s Jar file and JDK. It’s is not dependent on application server that’s makes it much lighter as compared to the EJB framework. The Applications developed under EJB were tightly-coupled i.e. if the other class object is created in the dependent class then there exist a Tight-coupling. Any changes in the class object leads to the change in the Dependent class. Spring is loosely-coupled because if we want any changes in the object of class then we just need to configure the spring configuration xml file (Spring manages objects). We need not to make any changes in the Dependent Class. Why Spring Framework not EJB’s
  • 10.
    Point of ComparisonEJB’s Spring Transaction Management Only JTA (Java Transaction API) is supported. Spring supports a wider range, including JTA, JDBC, Hibernate. Persistence In EJB it is tightly integrated with JPA (Java Persistence API) Spring supports a wider range that includes JPA, Hibernate, JDBC State Management Stateful Session Beans in EJB Spring it is indirectly dependent on container session management. AOP EJB provide limited support Spring is more robust support via AspectJ. Security EJB has support security through JAAS (Java Authentication and Authorization Service) Spring can go beyond JAAS, through ACEGI (security 2.0)
  • 11.
    Why Spring Framework? 1.Spring is the most popular application development framework for enterprise. Millions of developers around the world use Spring Framework to create high performing, easily testable, and reusable code. 2. Spring is lightweight when it comes to size and transparency. The basic version of Spring framework is around 2MB. 3. Spring framework is the extensions for building web applications on top of the Java EE platform. 4. Spring framework targets to make J2EE development easier to use and promotes good programming practices by enabling a POJO- based programming model.
  • 12.
    Versions of SpringFramework Version Year Features 0.9 2002 1.0 2003 AOP , Application context concept, DAO support, JDBC abstraction, Hibernate support, etc 2.0 2006 IoC container, Easier XML configuration, Easier AOP XML configuration, Tag library for Spring MVC, etc 3.0 2009 Spring Expression Language, IoC enhancements, Object to XML mapping, @MVC additions, etc 4.0 2013 Core Container Improvements, General Web Improvements, WebSocket and STOMP Messaging Testing Improvements, etc 5.0 2017 JDK baseline update, Core container updates. Functional programming with Kotlin. Testing improvements.
  • 13.
    Spring Architecture (Veryloosely coupled, components widely reusable) and separately packaged.
  • 14.
    1. Spring allowsto decouple software layers by injecting a component’s dependencies at runtime rather than having them declared at compile time. 2. Spring provides integration for J2EE services such as EJB, JDBC. It also integrates several popular ORM toolkits such as Hibernate and JDO and assorted other services as well. 3. Spring is built on the principle of unchecked exception handling. This also reduces code dependencies between layers. Spring provides a granular exception hierarchy for data access operations and maps JDBC, EJB, and ORM exceptions to Spring exceptions so that applications can get better information about the error condition.
  • 15.
    Core Container 1. TheCore module provides the fundamental parts of the framework, including the IoC and Dependency Injection features. 2. The Bean module provides BeanFactory, which is a sophisticated implementation of the factory pattern. 3. The Context module builds on the solid base provided by the Core and Beans modules and it is a medium to access any objects defined and configured. The ApplicationContext interface is the focal point of the Context module. 4. The SpEL module provides a powerful expression language for querying and manipulating an object graph at runtime.
  • 16.
    Data Access/Integration 1. TheJDBC module provides a JDBC-abstraction layer that removes the need for tedious JDBC related coding. 2. The ORM module provides integration layers for popular object- relational mapping APIs, including JDO, Hibernate. 3. The OXM module provides an abstraction layer that supports Object/XML mapping implementations for XMLBeans. 4. The Java Messaging Service JMS module contains features for producing and consuming messages. 5. The Transaction module supports programmatic and declarative transaction management for classes that implement special interfaces and for all your POJOs.
  • 17.
    Web 1. The Webmodule provides basic web-oriented integration features such as multipart file-upload functionality and the initialization of the IoC container using servlet listeners and a web-oriented application context. 2. The Web-MVC module contains Spring's Model-View-Controller (MVC) implementation for web applications. 3. The Web-Socket module provides support for WebSocket-based, two-way communication between the client and the server in web applications. 4. The Web-Portlet module provides the MVC implementation to be used in a portlet environment and mirrors the functionality of Web- Servlet module.
  • 18.
    Miscellaneous 1. The AOPmodule provides an aspect-oriented programming implementation allowing you to define method-interceptors and pointcuts to cleanly decouple code. 2. The Aspects module provides integration with AspectJ, which is again a powerful and mature AOP framework. 3. The Instrumentation module provides class instrumentation support and class loader implementations to be used in certain application servers. 4. The Messaging module provides support for STOMP as the WebSocket sub-protocol to use in applications. 5. The Test module supports the testing of Spring components with frameworks.
  • 19.
    What is MVC(ModelView Controller) 1. It follow the software Architectural pattern. 2. One of the most frequently used pattern. 3. Separate application functionality.
  • 20.
    Model: (All BusinessLogic ) Pogo, Business Object, DAO classes 1. Data related logic 2. Interaction with database (INSERT,DELETE,UPDATE,SELECT) 3. Communication with Controller. 4. Can sometimes update the View View: (Presentation View)  jsp, html, css 1. What the end user see. 2. Usually consist of HTML/CSS 3. Communicate with Controller. 4. Template Engine for variables Controller: (request , response) Servlet 1. Receives request from View (url form) 2. Process the request. 3. Gets data from Model. 4. Response with data to the View.
  • 21.
    Flow Control inSpring MVC
  • 22.
    1. We haveController which handle the request coming from client, but the controller don’t get request directly, first the request is passed (filtered) from the Dispatcher-Servlet. 2. The Dispatcher-Servlet is also known as Front-Controller provided by Spring Framework and it is present inside the web.xml file. 3. The Dispatcher-Servlet or Front-Controller get to know about what client has requested for, with the help of Configuration File (configSpring.xml). 4. The Configuration File has all the mapping information for Controller through Front-Controller. 5. And based on that mapping the response is generated by the Controller and transferred to the Client.
  • 24.
    Advantages of SpringMVC 1. 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. 2. Light-weight - It uses light-weight servlet container to develop and deploy your application. 3. 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. 4. Rapid development - The Spring MVC facilitates fast and parallel development.
  • 25.
    5. Reusable businesscode - Instead of creating new objects, it allows us to use the existing business objects. 6. Easy to test - In Spring, generally we create JavaBeans classes that enable you to inject test data using the setter methods. 7. Flexible Mapping - It provides the specific annotations that easily redirect the page.
  • 26.
    IDE’S (Integrated DevelopmentEnvironment’s) Available 1. Eclipse Step 1: Click on File Step 2: Select New Step 3: Click on Other… 1. Eclipse 2. NetBeans 3. IntelliJ IDEA etc Project Setup in Eclipse and NetBeans
  • 28.
    Step 4: Clickon Maven Project Step 5: Click on Next
  • 29.
    Step 6: Browseand Set the default location for saving files Step 7: Click on Next
  • 30.
    Step 8: Selectthe webapp Group Id and Artifact Id Step 9: Click on Next
  • 31.
    Step 10: GiveArtifact Name Step 11: Click on Finish
  • 32.
    2. NetBeans Step 1:Click on New Project Step 2: Select Java Web Step 3: Select Web Application Step 4: Click on Next
  • 33.
    Step 5: GiveProject Name Step 6: Click on Next
  • 34.
    Step 7: Selectthe Server Step 8: Click on Next
  • 35.
    Step 9: Selectthe Spring Web MVC Step 10: Click on Finish
  • 36.
    Example 1. POJO (PLAINOLD JAVA OBJECT)
  • 37.
  • 38.