SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
By→ Anuj Kumar Singh
What is Spring ?
1. Spring Framework is a open source Java Platform that provides
comprehensive infrastructure support for developing robust Java
application very easily and rapidly.
2. Spring framework was developed by Rod Johnson and was first
released in 2003 in Spring Organization now Pivotal.
3. Earlier name of Spring Framework was Interface21 later changed to
Spring based on Spring season.
4. Spring Framework is replacement of EJB’s (Enterprise Java Beans)
because of heavy weight of EJB’s
Why Spring ?
1. Spring is the most popular application development framework for
enterprise Java. 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. The core features of the Spring Framework can be used in
developing any Java application, but there are 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.
Advantages of Spring
1. Lightweight - Spring framework is lightweight because of its POJO
implementation.The Spring framework doesn’t force any
programmer to inherit any class or implements any interface. That
is why it is said non-invasive, Enable you to write powerful, scalable
applications using POJO.
2. Easy to develop J2EE application - The Dependency Injection
feature of Spring Framework and it support to various frameworks
makes the easy development of JavaEE application.
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.
1. Loose Coupling - The Spring applications are loosely coupled
because of dependency injection and handles injecting dependent
components without a component knowing where they came from
(IoC).
2. Powerful abstraction - It provides powerful abstraction to JavaEE
specifications such as JDBC.
3. Declarative support - It provides declarative support for caching,
validation, transactions and formatting.
4. Portable - can use server - side in web/ejb app, client-side in swing
app, business logic is completely portable.
5. Lifecycle - Responsible for managing all your application
components, particularly those in the middle tier container sees
components through well-defined lifecycle: init(), destroy()
Modules of the Spring Framework
1. Core - Inversion of Control (IoC) and Dependency Injection.
2. AOP - These modules support aspect oriented programming
implementation where you can use Advices, Pointcuts etc. to
decouple the code.
3. DAO - Data Access Object support, transaction management,
JDBC-abstraction
4. ORM - Object Relational Mapping data access, integration layers
for Hibernate
5. MVC - Model-View-Controller implementation for web applications
6. 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.
IOC and Dependency Injection
1. Dependency Injection is the main functionality provided by Spring
IOC (Inversion of Control).
2. The Spring-Core module is responsible for injecting dependencies
through either Constructor or Setter methods in POJO class.
3. Dependency Injection in Spring also ensures loose-coupling
between the classes.
Need for Dependency Injection:
1. Spring IOC resolves dependencies with Dependency Injection,
which makes the code easier to test and reuse.
2. Loose coupling between classes can be possible by defining
interfaces for common functionality and the injector will instantiate
the objects of required implementation.
Example
Tightly Coupling - (without IOC)
class Employee{
Address address;
Employee()
{address=new Address(“xyz street”, ”Lucknow”, ”UP”);
}}
One class object is created in another class in tight coupling.Leads to
a.Stop server
b.Recomplie
c.Create jar and war file
d.Redeploy
e.Restart the server.
Loose Coupling
1. with IOC (Constructor Injection)
class Employee{
Address address;
Employee(Address address)
{this.address=address;} }
2. with IOC (Setter Injection)
class Employee{
Address address;
public void setAddress(Address address)
{this.address=address;} }
No need to stop the existing component, in real time it is better.
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 via importing and instantiating classes.
2. Spring provides integration for J2EE services such as EJB, JDBC,
JNDI, JMS, JTA. It also integrates several popular ORM toolkits
such as Hibernate and JDO and assorted other services as well.
3. One of the highly touted
4. 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.
Flow Control in Spring
How to Start Using Spring
1. create the class
2. create the xml file to provide the values
3. create the test class
4. Load the spring jar files
5. Run the test class
1. CLASS FILE - POJO (PLAIN OLD JAVA OBJECT)
2. TEST FILE - DAO (DATA ACCESS OBJECT)
3. BEAN FILE - XML
4. Load the jar files required for spring framework
There are mainly three jar files required to run this application.
1. org.springframework.core-3.0.1.RELEASE-A
2. com.springsource.org.apache.commons.logging-1.1.1
3. org.springframework.beans-3.0.1.RELEASE-A
5. Run the TEST FILE
Containers in Spring
1. Core Container (slower)
a. It is called Lazy Container.
b. It create object on demand one by one.
c. It will create the object when the bean file is loaded.
ClassPathResource res=new ClassPathResource(“Spring.xml”);
XmlBeanFactory fact=new XmlBeanFactory(res);
fact.getBean(“abc”);
2. J2EE Container (faster)
a. It is called Eager Container.
b. It create all object at once.
c. It cerate the object as soon as object of ApplicationContext is made.
ApplicationContext con=new
ClassPathXmlApplicationContext(“Spring.xml”);
Bean File
• Typical java bean with a unique id
• In spring there are basically two types
1. Singleton
One instance of the bean created and referenced each time it
is requested
<bean class=“bean.Test” id=“t” scope=“singleton”>
One object for all caller.
2. Prototype (non-singleton)
<bean class=“bean.Test” id=“t” scope=“prototype”>
multiple object i.e. one one object for each caller.
Spring framework Introduction

Mais conteúdo relacionado

Mais procurados

Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
Java spring framework
Java spring frameworkJava spring framework
Java spring frameworkRajiv Gupta
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkASG
 
Spring Framework
Spring FrameworkSpring Framework
Spring Frameworknomykk
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
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
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
Spring framework-tutorial
Spring framework-tutorialSpring framework-tutorial
Spring framework-tutorialvinayiqbusiness
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Springboot introduction
Springboot introductionSpringboot introduction
Springboot introductionSagar Verma
 
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 IoCFunnelll
 

Mais procurados (20)

Spring framework core
Spring framework coreSpring framework core
Spring framework core
 
Spring User Guide
Spring User GuideSpring User Guide
Spring User Guide
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
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
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Apache Ant
Apache AntApache Ant
Apache Ant
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Spring framework-tutorial
Spring framework-tutorialSpring framework-tutorial
Spring framework-tutorial
 
Spring boot
Spring bootSpring boot
Spring boot
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Springboot introduction
Springboot introductionSpringboot introduction
Springboot introduction
 
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
 

Semelhante a Spring framework Introduction

Spring framework Introduction
Spring framework  IntroductionSpring framework  Introduction
Spring framework IntroductionAnuj Singh Rajput
 
Spring framework
Spring frameworkSpring framework
Spring frameworkKani Selvam
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크Yoonki Chang
 
Spring framework
Spring frameworkSpring framework
Spring frameworkvietduc17
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsVirtual Nuggets
 
Spring (1)
Spring (1)Spring (1)
Spring (1)Aneega
 
spring framework ppt by Rohit malav
spring framework ppt by Rohit malavspring framework ppt by Rohit malav
spring framework ppt by Rohit malavRohit malav
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkDineesha Suraweera
 
Learn Spring Boot With Bisky - Intoduction
Learn Spring Boot With Bisky - IntoductionLearn Spring Boot With Bisky - Intoduction
Learn Spring Boot With Bisky - IntoductionMarshallChabaga
 
How Spring Framework Really Works?
How Spring Framework Really Works?How Spring Framework Really Works?
How Spring Framework Really Works?NexSoftsys
 
The Complete Spring Tutorial
The Complete Spring TutorialThe Complete Spring Tutorial
The Complete Spring Tutorialcribes
 
Spring Architecture | Advanced Java
Spring Architecture | Advanced JavaSpring Architecture | Advanced Java
Spring Architecture | Advanced JavaVISHAL DONGA
 

Semelhante a Spring framework Introduction (20)

Spring framework Introduction
Spring framework  IntroductionSpring framework  Introduction
Spring framework Introduction
 
Spring notes
Spring notesSpring notes
Spring notes
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
스프링 프레임워크
스프링 프레임워크스프링 프레임워크
스프링 프레임워크
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Springs_Training
Springs_TrainingSprings_Training
Springs_Training
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 
spring framework ppt by Rohit malav
spring framework ppt by Rohit malavspring framework ppt by Rohit malav
spring framework ppt by Rohit malav
 
Month 3 report
Month 3 reportMonth 3 report
Month 3 report
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Learn Spring Boot With Bisky - Intoduction
Learn Spring Boot With Bisky - IntoductionLearn Spring Boot With Bisky - Intoduction
Learn Spring Boot With Bisky - Intoduction
 
Spring
SpringSpring
Spring
 
How Spring Framework Really Works?
How Spring Framework Really Works?How Spring Framework Really Works?
How Spring Framework Really Works?
 
The Complete Spring Tutorial
The Complete Spring TutorialThe Complete Spring Tutorial
The Complete Spring Tutorial
 
Spring Architecture | Advanced Java
Spring Architecture | Advanced JavaSpring Architecture | Advanced Java
Spring Architecture | Advanced Java
 
Spring Framework Rohit
Spring Framework RohitSpring Framework Rohit
Spring Framework Rohit
 

Mais de Anuj Singh Rajput (20)

Web technology
Web technologyWeb technology
Web technology
 
Java script
Java scriptJava script
Java script
 
Html (hypertext markup language)
Html (hypertext markup language)Html (hypertext markup language)
Html (hypertext markup language)
 
Css
CssCss
Css
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Jsp session 13
Jsp   session 13Jsp   session 13
Jsp session 13
 
Jsp session 12
Jsp   session 12Jsp   session 12
Jsp session 12
 
Jsp session 11
Jsp   session 11Jsp   session 11
Jsp session 11
 
Jsp session 10
Jsp   session 10Jsp   session 10
Jsp session 10
 
Jsp session 9
Jsp   session 9Jsp   session 9
Jsp session 9
 
Jsp session 8
Jsp   session 8Jsp   session 8
Jsp session 8
 
Jsp session 7
Jsp   session 7Jsp   session 7
Jsp session 7
 
Jsp session 6
Jsp   session 6Jsp   session 6
Jsp session 6
 
Jsp session 5
Jsp   session 5Jsp   session 5
Jsp session 5
 
Jsp session 4
Jsp   session 4Jsp   session 4
Jsp session 4
 
Jsp session 3
Jsp   session 3Jsp   session 3
Jsp session 3
 
Jsp session 2
Jsp   session 2Jsp   session 2
Jsp session 2
 
Jsp session 1
Jsp   session 1Jsp   session 1
Jsp session 1
 
Servlet session 14
Servlet   session 14Servlet   session 14
Servlet session 14
 
Servlet session 13
Servlet   session 13Servlet   session 13
Servlet session 13
 

Último

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Último (20)

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Spring framework Introduction

  • 2. What is Spring ? 1. Spring Framework is a open source Java Platform that provides comprehensive infrastructure support for developing robust Java application very easily and rapidly. 2. Spring framework was developed by Rod Johnson and was first released in 2003 in Spring Organization now Pivotal. 3. Earlier name of Spring Framework was Interface21 later changed to Spring based on Spring season. 4. Spring Framework is replacement of EJB’s (Enterprise Java Beans) because of heavy weight of EJB’s
  • 3. Why Spring ? 1. Spring is the most popular application development framework for enterprise Java. 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. The core features of the Spring Framework can be used in developing any Java application, but there are 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.
  • 4. Advantages of Spring 1. Lightweight - Spring framework is lightweight because of its POJO implementation.The Spring framework doesn’t force any programmer to inherit any class or implements any interface. That is why it is said non-invasive, Enable you to write powerful, scalable applications using POJO. 2. Easy to develop J2EE application - The Dependency Injection feature of Spring Framework and it support to various frameworks makes the easy development of JavaEE application. 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.
  • 5. 1. Loose Coupling - The Spring applications are loosely coupled because of dependency injection and handles injecting dependent components without a component knowing where they came from (IoC). 2. Powerful abstraction - It provides powerful abstraction to JavaEE specifications such as JDBC. 3. Declarative support - It provides declarative support for caching, validation, transactions and formatting. 4. Portable - can use server - side in web/ejb app, client-side in swing app, business logic is completely portable. 5. Lifecycle - Responsible for managing all your application components, particularly those in the middle tier container sees components through well-defined lifecycle: init(), destroy()
  • 6. Modules of the Spring Framework 1. Core - Inversion of Control (IoC) and Dependency Injection. 2. AOP - These modules support aspect oriented programming implementation where you can use Advices, Pointcuts etc. to decouple the code. 3. DAO - Data Access Object support, transaction management, JDBC-abstraction 4. ORM - Object Relational Mapping data access, integration layers for Hibernate 5. MVC - Model-View-Controller implementation for web applications 6. 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.
  • 7. IOC and Dependency Injection 1. Dependency Injection is the main functionality provided by Spring IOC (Inversion of Control). 2. The Spring-Core module is responsible for injecting dependencies through either Constructor or Setter methods in POJO class. 3. Dependency Injection in Spring also ensures loose-coupling between the classes. Need for Dependency Injection: 1. Spring IOC resolves dependencies with Dependency Injection, which makes the code easier to test and reuse. 2. Loose coupling between classes can be possible by defining interfaces for common functionality and the injector will instantiate the objects of required implementation.
  • 8. Example Tightly Coupling - (without IOC) class Employee{ Address address; Employee() {address=new Address(“xyz street”, ”Lucknow”, ”UP”); }} One class object is created in another class in tight coupling.Leads to a.Stop server b.Recomplie c.Create jar and war file d.Redeploy e.Restart the server.
  • 9. Loose Coupling 1. with IOC (Constructor Injection) class Employee{ Address address; Employee(Address address) {this.address=address;} } 2. with IOC (Setter Injection) class Employee{ Address address; public void setAddress(Address address) {this.address=address;} } No need to stop the existing component, in real time it is better.
  • 10. Spring Architecture (Very loosely coupled, components widely reusable) and separately packaged.
  • 11. 1. Spring allows to decouple software layers by injecting a component’s dependencies at runtime rather than having them declared at compile time via importing and instantiating classes. 2. Spring provides integration for J2EE services such as EJB, JDBC, JNDI, JMS, JTA. It also integrates several popular ORM toolkits such as Hibernate and JDO and assorted other services as well. 3. One of the highly touted 4. 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.
  • 12. Flow Control in Spring
  • 13. How to Start Using Spring 1. create the class 2. create the xml file to provide the values 3. create the test class 4. Load the spring jar files 5. Run the test class
  • 14. 1. CLASS FILE - POJO (PLAIN OLD JAVA OBJECT)
  • 15. 2. TEST FILE - DAO (DATA ACCESS OBJECT)
  • 16. 3. BEAN FILE - XML
  • 17. 4. Load the jar files required for spring framework There are mainly three jar files required to run this application. 1. org.springframework.core-3.0.1.RELEASE-A 2. com.springsource.org.apache.commons.logging-1.1.1 3. org.springframework.beans-3.0.1.RELEASE-A 5. Run the TEST FILE
  • 18. Containers in Spring 1. Core Container (slower) a. It is called Lazy Container. b. It create object on demand one by one. c. It will create the object when the bean file is loaded. ClassPathResource res=new ClassPathResource(“Spring.xml”); XmlBeanFactory fact=new XmlBeanFactory(res); fact.getBean(“abc”); 2. J2EE Container (faster) a. It is called Eager Container. b. It create all object at once. c. It cerate the object as soon as object of ApplicationContext is made. ApplicationContext con=new ClassPathXmlApplicationContext(“Spring.xml”);
  • 19. Bean File • Typical java bean with a unique id • In spring there are basically two types 1. Singleton One instance of the bean created and referenced each time it is requested <bean class=“bean.Test” id=“t” scope=“singleton”> One object for all caller. 2. Prototype (non-singleton) <bean class=“bean.Test” id=“t” scope=“prototype”> multiple object i.e. one one object for each caller.