SlideShare a Scribd company logo
1 of 12
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, in
broader sense, 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. We
will learn these modules in next page. Let's understand
the IOC and Dependency Injection first.
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. Let's understand
this with the following code:
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.
• Advantage of Dependency Injection
– makes the code loosely coupled so easy to maintain
– makes the code easy to test
Advantages of Spring Framework
• 1) 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.
• Let's take the example of 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.
• 2) Loose Coupling
– The Spring applications are loosely coupled because of dependency
injection.
• 3) 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.
• 4) Lightweight
– Spring framework is lightweight because of its POJO
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.
• 5) Fast Development
– The Dependency Injection feature of Spring Framework
and it support to various frameworks makes the easy
development of JavaEE application.
• 6) Powerful abstraction
– It provides powerful abstraction to JavaEE specifications
such as JMS, JDBC, JPA and JTA.
• 7) Declarative support
– It provides declarative support for caching, validation,
transactions and formatting.
Spring Modules
• The Spring Framework consists of features
organized into about 20 modules. These
modules are grouped into Core Container,
Data Access/Integration, Web, AOP (Aspect
Oriented Programming), Instrumentation, and
Test, as shown in the following diagram.
• Test
– This layer provides support of testing with JUnit and
TestNG.
• Spring Core Container
– The Spring Core container contains core, beans, context
and expression language (EL) modules.
– Core and Beans
• These modules provide IOC and Dependency Injection features.
– Context
• This module supports internationalization (I18N), EJB, JMS, Basic
Remoting.
– Expression Language
• 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
– These modules support aspect oriented programming
implementation where you can use Advices, Pointcuts etc. to
decouple the code.
– The aspects module provides support to integration with
AspectJ.
– The instrumentation module provides support to class
instrumentation and classloader implementations.
• Data Access / Integration
– This group comprises of JDBC, ORM, OXM, JMS and Transaction
modules. These modules basically provide support to interact
with the database.
• Web
– This group comprises of Web, Web-Servlet, Web-Struts and
Web-Portlet. These modules provide support to create web
application.
IoC Container
• The IoC container is responsible to instantiate,
configure and assemble the objects. The IoC
container gets informations from the XML file and
works accordingly. The main tasks performed by
IoC container are:
– to instantiate the application class
– to configure the object
– to assemble the dependencies between the objects
• There are two types of IoC containers. They are:
– BeanFactory
– ApplicationContext
Difference between BeanFactory and
the ApplicationContext
• The org.springframework.beans.factory.
BeanFactory and the org.springframework.context.
ApplicationContext interfaces acts as the IoC container.
The ApplicationContext interface is built on top of the
BeanFactory interface. It adds some extra functionality
than BeanFactory such as simple integration with
Spring's AOP, message resource handling (for I18N),
event propagation, application layer specific context
(e.g. WebApplicationContext) for web application. So it
is better to use ApplicationContext than BeanFactory.

More Related Content

What's hot

Concepts of Asp.Net
Concepts of Asp.NetConcepts of Asp.Net
Concepts of Asp.Net
vidyamittal
 

What's hot (20)

Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
JSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End FrameworksJSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End Frameworks
 
Webapplication ppt prepared by krishna ballabh gupta
Webapplication ppt prepared by krishna ballabh guptaWebapplication ppt prepared by krishna ballabh gupta
Webapplication ppt prepared by krishna ballabh gupta
 
Devjyotippt
DevjyotipptDevjyotippt
Devjyotippt
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Best Practices for JSF, Gameduell 2013
Best Practices for JSF, Gameduell 2013Best Practices for JSF, Gameduell 2013
Best Practices for JSF, Gameduell 2013
 
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
JavaCro'14 - Consuming Java EE Backends in Desktop, Web, and Mobile Frontends...
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architecture
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Getting Started with Spring Framework
Getting Started with Spring FrameworkGetting Started with Spring Framework
Getting Started with Spring Framework
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS
 
Concepts of Asp.Net
Concepts of Asp.NetConcepts of Asp.Net
Concepts of Asp.Net
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
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
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Java Training in Chennai
Java Training in Chennai Java Training in Chennai
Java Training in Chennai
 

Similar to 1. Spring intro IoC

Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
Sujit Kumar
 
Spring framework
Spring frameworkSpring framework
Spring framework
Kani Selvam
 
The Complete Spring Tutorial
The Complete Spring TutorialThe Complete Spring Tutorial
The Complete Spring Tutorial
cribes
 

Similar to 1. Spring intro IoC (20)

Spring ppt
Spring pptSpring ppt
Spring ppt
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
spring
springspring
spring
 
Spring
SpringSpring
Spring
 
Spring
SpringSpring
Spring
 
Month 3 report
Month 3 reportMonth 3 report
Month 3 report
 
Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
Framework adoption for java enterprise application development
Framework adoption for java enterprise application developmentFramework adoption for java enterprise application development
Framework adoption for java enterprise application development
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring notes
Spring notesSpring notes
Spring notes
 
Java Spring
Java SpringJava Spring
Java Spring
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
The Complete Spring Tutorial
The Complete Spring TutorialThe Complete Spring Tutorial
The Complete Spring Tutorial
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Suman
SumanSuman
Suman
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

[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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

1. Spring intro IoC

  • 1.
  • 2. 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, in broader sense, 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. We will learn these modules in next page. Let's understand the IOC and Dependency Injection first.
  • 3. 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. Let's understand this with the following code: class Employee{ Address address; Employee(){ address=new Address(); } } • In such case, there is dependency between the Employee and Address (tight coupling).
  • 4. • 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. • Advantage of Dependency Injection – makes the code loosely coupled so easy to maintain – makes the code easy to test
  • 5. Advantages of Spring Framework • 1) 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. • Let's take the example of 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. • 2) Loose Coupling – The Spring applications are loosely coupled because of dependency injection. • 3) 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.
  • 6. • 4) Lightweight – Spring framework is lightweight because of its POJO 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. • 5) Fast Development – The Dependency Injection feature of Spring Framework and it support to various frameworks makes the easy development of JavaEE application. • 6) Powerful abstraction – It provides powerful abstraction to JavaEE specifications such as JMS, JDBC, JPA and JTA. • 7) Declarative support – It provides declarative support for caching, validation, transactions and formatting.
  • 7. Spring Modules • The Spring Framework consists of features organized into about 20 modules. These modules are grouped into Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation, and Test, as shown in the following diagram.
  • 8.
  • 9. • Test – This layer provides support of testing with JUnit and TestNG. • Spring Core Container – The Spring Core container contains core, beans, context and expression language (EL) modules. – Core and Beans • These modules provide IOC and Dependency Injection features. – Context • This module supports internationalization (I18N), EJB, JMS, Basic Remoting. – Expression Language • 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.
  • 10. • AOP, Aspects and Instrumentation – These modules support aspect oriented programming implementation where you can use Advices, Pointcuts etc. to decouple the code. – The aspects module provides support to integration with AspectJ. – The instrumentation module provides support to class instrumentation and classloader implementations. • Data Access / Integration – This group comprises of JDBC, ORM, OXM, JMS and Transaction modules. These modules basically provide support to interact with the database. • Web – This group comprises of Web, Web-Servlet, Web-Struts and Web-Portlet. These modules provide support to create web application.
  • 11. IoC Container • The IoC container is responsible to instantiate, configure and assemble the objects. The IoC container gets informations from the XML file and works accordingly. The main tasks performed by IoC container are: – to instantiate the application class – to configure the object – to assemble the dependencies between the objects • There are two types of IoC containers. They are: – BeanFactory – ApplicationContext
  • 12. Difference between BeanFactory and the ApplicationContext • The org.springframework.beans.factory. BeanFactory and the org.springframework.context. ApplicationContext interfaces acts as the IoC container. The ApplicationContext interface is built on top of the BeanFactory interface. It adds some extra functionality than BeanFactory such as simple integration with Spring's AOP, message resource handling (for I18N), event propagation, application layer specific context (e.g. WebApplicationContext) for web application. So it is better to use ApplicationContext than BeanFactory.