SlideShare a Scribd company logo
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!
Ad

More Related Content

What's hot (20)

Spring Framework
Spring FrameworkSpring Framework
Spring Framework
nomykk
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Pei-Tang Huang
 
Managing APIs with MuleSoft
Managing APIs with MuleSoftManaging APIs with MuleSoft
Managing APIs with MuleSoft
Guilherme Pereira Silva
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
NexThoughts Technologies
 
Jetpack Compose beginner.pdf
Jetpack Compose beginner.pdfJetpack Compose beginner.pdf
Jetpack Compose beginner.pdf
AayushmaAgrawal
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
Mehul Jariwala
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
tola99
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Trey Howard
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
Ramon Ribeiro Rabello
 
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Edureka!
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Spring framework aop
Spring framework aopSpring framework aop
Spring framework aop
Taemon Piya-Lumyong
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
Funnelll
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
AnushaNaidu
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
Rajiv Gupta
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
Jesus Perez Franco
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
nomykk
 
Jetpack Compose beginner.pdf
Jetpack Compose beginner.pdfJetpack Compose beginner.pdf
Jetpack Compose beginner.pdf
AayushmaAgrawal
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
Vinay Kumar
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
tola99
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Trey Howard
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
Ramon Ribeiro Rabello
 
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Edureka!
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
Funnelll
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
Rajiv Gupta
 

Similar to Spring framework (20)

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
Sujit Kumar
 
Spring - a framework written by developers
Spring - a framework written by developersSpring - a framework written by developers
Spring - a framework written by developers
MarcioSoaresPereira1
 
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
Hitesh-Java
 
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
PawanMM
 
Spring session
Spring sessionSpring session
Spring session
Gamal Shaban
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
NourhanTarek23
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
ThirupathiReddy Vajjala
 
Spring framework
Spring frameworkSpring framework
Spring framework
Kani Selvam
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
ASG
 
Spring framework
Spring frameworkSpring framework
Spring framework
Shivi Kashyap
 
Spring framework
Spring frameworkSpring framework
Spring framework
Rajkumar Singh
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
AnushaNaidu
 
Brownbag001 spring ioc from 2012
Brownbag001 spring ioc from 2012Brownbag001 spring ioc from 2012
Brownbag001 spring ioc from 2012
Timothy Spann
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
Yoonki Chang
 
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
Arjun Thakur
 
Springs_Training
Springs_TrainingSprings_Training
Springs_Training
KAMALA KOLLURI
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
natashasweety7
 
Spring framework
Spring frameworkSpring framework
Spring framework
vietduc17
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
Sujit Kumar
 
Spring - a framework written by developers
Spring - a framework written by developersSpring - a framework written by developers
Spring - a framework written by developers
MarcioSoaresPereira1
 
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
Hitesh-Java
 
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
PawanMM
 
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
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
ASG
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
AnushaNaidu
 
Brownbag001 spring ioc from 2012
Brownbag001 spring ioc from 2012Brownbag001 spring ioc from 2012
Brownbag001 spring ioc from 2012
Timothy Spann
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
Yoonki Chang
 
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
Arjun Thakur
 
Spring framework
Spring frameworkSpring framework
Spring framework
vietduc17
 
Ad

Recently uploaded (20)

Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Ad

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