SlideShare a Scribd company logo
1 of 17
Spring Framework
Sonal Poddar
sonalpoddar@hotmail.com
Content
• What is Spring Framework?
• Key features of Spring Framework
 Spring Modules
 Dependency Injection and Inversion of Control
 Spring AOP
• Spring Environment Setup
• Quick Steps to Develop Spring Application
• Spring Hello World Example
• Setter Injection v/s Constructor Injection
• Spring Autowiring
What is Spring Framework?
• Spring is a light weight and open source framework created
by Rod Johnson in 2003
• It is a framework of frameworks
• Spring framework is said to be a non-invasive.
• Spring Framework made J2EE application development little
easier, by introducing POJO model
• Spring having so much of demand because of the following 3
reasons….
 Simplicity
 Testability
 Loose Coupling
Key features of Spring Framework
Spring Modules
 Test
 Core Container
 AOP
 Aspects
 Instrumentation
 Data Access/ Integration
 Web (MVC / Remoting)
Spring Core Module – Loose Coupling
Tight Coupling
When an object creates the object to be used, then it is a tight coupling
situation.
As the main object creates the object itself, this object can not be changed
from outside world easily marked it as tightly coupled objects.
When an object gets the object to be used from the outside, then it is a loose
coupling situation.
As the main object is merely using the object, this object can be changed
from the outside world easily marked it as loosely coupled objects.
Loose Coupling
IoC and Dependency Injection
What is Inversion of Control ?
Inversion of Control is a principle in software engineering by which the control
of objects or portions of a program is transferred to a container or framework.
It's most often used in the context of object-oriented programming.
Inversion of Control can be achieved through various mechanisms such as:
Strategy design pattern, Service Locator pattern, Factory pattern, and
Dependency Injection (DI).
IoC and Dependency Injection (cont.)
What is Spring IoC Container ?
• An IoC container is a common characteristic of frameworks that implement
IoC.
• In the Spring framework, the IoC container is represented by the interface
ApplicationContext.
• The Spring container is responsible for instantiating, configuring and
assembling objects known as beans, as well as managing their lifecycle.
• The Spring framework provides several implementations of the
ApplicationContext interface — ClassPathXmlApplicationContext and
FileSystemXmlApplicationContext for standalone applications, and
WebApplicationContext for web applications.
• Here's one way to manually instantiate a container:
IoC and Dependency Injection (cont.)
Spring IoC Container Overview
• The configuration metadata can be represented either by;
 XML
 Java Annotations
IoC and Dependency Injection (cont.)
What is Dependency Injection?
Dependency injection is a pattern through which to implement IoC, where the
control being inverted is the setting of object's dependencies.
The act of connecting objects with other objects, or “injecting” objects into
other objects, is done by an assembler rather than by the objects themselves.
Traditional Programming Using DI
IoC and Dependency Injection (cont.)
Types of Dependency Injection
Spring framework provides two ways to inject dependency:-
 By Setter method
• In this type of injection, the spring container uses setter method in the
dependent class for injecting its dependencies (primitive values or any).
• Spring container knows whether to perform setter or constructor
injection by reading the information from an external file called spring
configuration file
• In spring config xml, we need to inform to the spring IOC container about
setter injection by using <property/>
 By Constructor
• In this type of injection, spring container uses constructor of the bean
class for assigning the dependencies.
• In spring config xml, we need to inform to the spring IOC container about
constructor injection by using <constructor –arg/>
Spring AOP
Introduction
• Aspect Oriented Programming (AOP) compliments OOPs in the sense that
it also provides modularity. But the key unit of modularity is aspect than
class.
• AOP breaks the program logic into distinct parts (called concerns). It is
used to increase modularity by cross-cutting concerns.
• A cross-cutting concern is a concern that can affect the whole application
and should be centralized in one location in code as possible, such as
transaction management, authentication, logging, security etc.
• It provides the pluggable way to dynamically add the additional concern
before, after or around the actual logic.
• AOP terminologies are Join point, Advice, Pointcut, Introduction,
Target Object, Aspect, Interceptor, AOP Proxy, Weaving
Spring Environment Setup
 Step 1 - Setup Java Development Kit (JDK)
You can download the latest version of SDK from Oracle's Java site
https://www.oracle.com/java/technologies/javase-downloads.html
 Step 2 - Install Apache Common Logging API
You can download the latest version of Apache Commons Logging API from
https://commons.apache.org/logging/
 Step 3 - Setup Eclipse IDE
To install Eclipse IDE, download the latest Eclipse binaries from
https://www.eclipse.org/downloads/
 Step 4 - Setup Spring Framework Libraries
Download the latest version of Spring framework libraries from
https://repo.spring.io/release/org/springframework/spring
Quick Steps to Develop Spring Application
• Spring environment starts by loading spring configuration xml file into Resource
Interface object.
• Actually this configuration file contains all bean configurations about our
application [ something like struts.xml in Struts 2 ]
• ClassPathResource is the implementation class of the Resource interface.
• Spring IOC container is called BeanFactory and this container is responsible for
creating the bean objects and for injecting it’s dependencies throughout our
applications.
• The XmlBeanFactory is the implementation class of the BeanFactory. There are
many methods in the BeanFactory interface. One method is getBean(), which
returns the object of the associated class.
• Syntax
Resource res = new ClassPathResource(“Our Config xml file name”);
BeanFactory factory = new XmlBeanFactory(res);
Spring Hello World Example
Demo in Eclipse
Using Setter Injection & Constructor Injection with Primitive Values
Setter Injection v/s Constructor Injection
 Partial dependency: can be injected using setter injection but it is not
possible by constructor. Suppose there are 3 properties in a class, having 3 arg
constructor and setters methods. In such case, if you want to pass information
for only one property, it is possible by setter method only.
 Overriding: Setter injection overrides the constructor injection. If we use
both constructor and setter injection, IOC container will use the setter
injection.
 Changes: We can easily change the value by setter injection. It doesn't
create a new bean instance always like constructor. So setter injection is
flexible than constructor injection.
Spring Autowiring
 Autowiring feature of spring framework enables you to inject the object
dependency implicitly.
 It internally uses setter or constructor injection.
 Autowiring can't be used to inject primitive values. It works with
reference only.
Autowiring Modes
• byName
• byType
• constructor
• autoDetect
• none
Thank You!

More Related Content

What's hot

Customizing nopCommerce with Plugins and Themes
Customizing nopCommerce with Plugins and ThemesCustomizing nopCommerce with Plugins and Themes
Customizing nopCommerce with Plugins and Themes
Gaines Kergosien
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski
 

What's hot (20)

Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Java Spring
Java SpringJava Spring
Java Spring
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Connecting Connect with Spring Boot
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Customizing nopCommerce with Plugins and Themes
Customizing nopCommerce with Plugins and ThemesCustomizing nopCommerce with Plugins and Themes
Customizing nopCommerce with Plugins and Themes
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 

Similar to Spring framework

Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
Sujit Kumar
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
NourhanTarek23
 
Spring framework
Spring frameworkSpring framework
Spring framework
Kani Selvam
 

Similar to Spring framework (20)

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI Beans
 
Spring session
Spring sessionSpring session
Spring session
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
 
Brownbag001 spring ioc from 2012
Brownbag001 spring ioc from 2012Brownbag001 spring ioc from 2012
Brownbag001 spring ioc from 2012
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Springs_Training
Springs_TrainingSprings_Training
Springs_Training
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-Core
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Spring framework

  • 2. Content • What is Spring Framework? • Key features of Spring Framework  Spring Modules  Dependency Injection and Inversion of Control  Spring AOP • Spring Environment Setup • Quick Steps to Develop Spring Application • Spring Hello World Example • Setter Injection v/s Constructor Injection • Spring Autowiring
  • 3. What is Spring Framework? • Spring is a light weight and open source framework created by Rod Johnson in 2003 • It is a framework of frameworks • Spring framework is said to be a non-invasive. • Spring Framework made J2EE application development little easier, by introducing POJO model • Spring having so much of demand because of the following 3 reasons….  Simplicity  Testability  Loose Coupling
  • 4. Key features of Spring Framework Spring Modules  Test  Core Container  AOP  Aspects  Instrumentation  Data Access/ Integration  Web (MVC / Remoting)
  • 5. Spring Core Module – Loose Coupling Tight Coupling When an object creates the object to be used, then it is a tight coupling situation. As the main object creates the object itself, this object can not be changed from outside world easily marked it as tightly coupled objects. When an object gets the object to be used from the outside, then it is a loose coupling situation. As the main object is merely using the object, this object can be changed from the outside world easily marked it as loosely coupled objects. Loose Coupling
  • 6. IoC and Dependency Injection What is Inversion of Control ? Inversion of Control is a principle in software engineering by which the control of objects or portions of a program is transferred to a container or framework. It's most often used in the context of object-oriented programming. Inversion of Control can be achieved through various mechanisms such as: Strategy design pattern, Service Locator pattern, Factory pattern, and Dependency Injection (DI).
  • 7. IoC and Dependency Injection (cont.) What is Spring IoC Container ? • An IoC container is a common characteristic of frameworks that implement IoC. • In the Spring framework, the IoC container is represented by the interface ApplicationContext. • The Spring container is responsible for instantiating, configuring and assembling objects known as beans, as well as managing their lifecycle. • The Spring framework provides several implementations of the ApplicationContext interface — ClassPathXmlApplicationContext and FileSystemXmlApplicationContext for standalone applications, and WebApplicationContext for web applications. • Here's one way to manually instantiate a container:
  • 8. IoC and Dependency Injection (cont.) Spring IoC Container Overview • The configuration metadata can be represented either by;  XML  Java Annotations
  • 9. IoC and Dependency Injection (cont.) What is Dependency Injection? Dependency injection is a pattern through which to implement IoC, where the control being inverted is the setting of object's dependencies. The act of connecting objects with other objects, or “injecting” objects into other objects, is done by an assembler rather than by the objects themselves. Traditional Programming Using DI
  • 10. IoC and Dependency Injection (cont.) Types of Dependency Injection Spring framework provides two ways to inject dependency:-  By Setter method • In this type of injection, the spring container uses setter method in the dependent class for injecting its dependencies (primitive values or any). • Spring container knows whether to perform setter or constructor injection by reading the information from an external file called spring configuration file • In spring config xml, we need to inform to the spring IOC container about setter injection by using <property/>  By Constructor • In this type of injection, spring container uses constructor of the bean class for assigning the dependencies. • In spring config xml, we need to inform to the spring IOC container about constructor injection by using <constructor –arg/>
  • 11. Spring AOP Introduction • Aspect Oriented Programming (AOP) compliments OOPs in the sense that it also provides modularity. But the key unit of modularity is aspect than class. • AOP breaks the program logic into distinct parts (called concerns). It is used to increase modularity by cross-cutting concerns. • A cross-cutting concern is a concern that can affect the whole application and should be centralized in one location in code as possible, such as transaction management, authentication, logging, security etc. • It provides the pluggable way to dynamically add the additional concern before, after or around the actual logic. • AOP terminologies are Join point, Advice, Pointcut, Introduction, Target Object, Aspect, Interceptor, AOP Proxy, Weaving
  • 12. Spring Environment Setup  Step 1 - Setup Java Development Kit (JDK) You can download the latest version of SDK from Oracle's Java site https://www.oracle.com/java/technologies/javase-downloads.html  Step 2 - Install Apache Common Logging API You can download the latest version of Apache Commons Logging API from https://commons.apache.org/logging/  Step 3 - Setup Eclipse IDE To install Eclipse IDE, download the latest Eclipse binaries from https://www.eclipse.org/downloads/  Step 4 - Setup Spring Framework Libraries Download the latest version of Spring framework libraries from https://repo.spring.io/release/org/springframework/spring
  • 13. Quick Steps to Develop Spring Application • Spring environment starts by loading spring configuration xml file into Resource Interface object. • Actually this configuration file contains all bean configurations about our application [ something like struts.xml in Struts 2 ] • ClassPathResource is the implementation class of the Resource interface. • Spring IOC container is called BeanFactory and this container is responsible for creating the bean objects and for injecting it’s dependencies throughout our applications. • The XmlBeanFactory is the implementation class of the BeanFactory. There are many methods in the BeanFactory interface. One method is getBean(), which returns the object of the associated class. • Syntax Resource res = new ClassPathResource(“Our Config xml file name”); BeanFactory factory = new XmlBeanFactory(res);
  • 14. Spring Hello World Example Demo in Eclipse Using Setter Injection & Constructor Injection with Primitive Values
  • 15. Setter Injection v/s Constructor Injection  Partial dependency: can be injected using setter injection but it is not possible by constructor. Suppose there are 3 properties in a class, having 3 arg constructor and setters methods. In such case, if you want to pass information for only one property, it is possible by setter method only.  Overriding: Setter injection overrides the constructor injection. If we use both constructor and setter injection, IOC container will use the setter injection.  Changes: We can easily change the value by setter injection. It doesn't create a new bean instance always like constructor. So setter injection is flexible than constructor injection.
  • 16. Spring Autowiring  Autowiring feature of spring framework enables you to inject the object dependency implicitly.  It internally uses setter or constructor injection.  Autowiring can't be used to inject primitive values. It works with reference only. Autowiring Modes • byName • byType • constructor • autoDetect • none