SlideShare a Scribd company logo
1 of 29
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
By Dinesh Radadiya
Spring Basics
By Mangalsinh Rajput
© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 Introduction
 Where we can use spring
 Spring Core Module
 Types of DI [Dependency Injection]
 Factory Methods
 Scope of bean
Agenda
2© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
3
Introduction
© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 Spring provide various level of support for developing
enterprise in Java applications. It simplifies many
different Java EE tasks.
 Spring allows loose coupling between classes so
developer can focus on solving the domain problem.
 To do this, we require someone who manage these
components and it’s dependencies.
Introduction
4© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
5© 2014 Knowarth
Introduction
 This is done by Container which is commonly used in
EE, is also used by Spring and is called “IoC” (Inversion
of Control) Container. Sequential and Parallel
Execution Support.
 Spring provides a Container/Factory which manages
component instantiation and initialization and
component dependencies.
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
6© 2013 Knowarth
Where we can use spring
Spring Basics
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
7© 2013 Knowarth
Spring Basics
Spring framework can be used to develop end to end
application
DAO
Spring DAO
Using Spring
Support for
JDBC
ORM
Hibernate
JPA
iBatis JEE
JMS
EJBs
WEB
Struts
JSF
Jasper Report
Freemarker
Spring MVC
AOP
Spring AOP
AspectJ Integration
Core
IoC Container
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
8© 2013 Knowarth
 In typical Java application we can use Spring in
following various levels.
 Web Layer : Struts 1, Struts2, JSF, Spring MVC
 Business Layer : EJBs, Web Services, Spring
 Domain Layer : Hibernate, Spring JDBC Templates
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
9© 2014 Knowarth
 Spring is a lightweight JEE framework designed to
provide louse coupling between components and a
POJO model.
 Spring provides a Container which manages business
objects and their lifecycle. Dependencies between
various components are supplied via some XML
configurations.
 Spring Container is factory object in memory making is
truly lightweight.
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
10
SPRING CORE MODULE
© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 Dependency Injection (IoC - Inversion of Control)
It is a process in which objects define their dependencies,
means , the other objects they work with it.
The container then injects those dependencies when it
creates the bean.
This process is fundamentally the inverse, hence the
name Inversion of Control (IoC).
This is achieved by XML file that specifies which beans
are created and what their properties are.
SPRING CORE MODULE
11© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 IoC container is an implementation of BeanFactory
interface.
 Extension of above interface is ApplicationContext and
WebApplicationContext interfaces.
 The most commonly used form of IoC container is the
ApplicationContext implementation.
 Container will get configurations from XML files.
SPRING CORE MODULE
12© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
13
TYPES OF DI
© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 Setter injection
 Constructor injection
 Defining a BEAN Objects whose implementations are
likely to change are defined in XML file.
 Use the <bean> tag to define object’s name and class
 Use nested <property> or <constructor-arg> elements
to assign values to the object
TYPES OF DI
14© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 First create a file called spring.xml and put it in “src”
folder of your project.
 In that case you can instantiate container with more
than one way let’s see it in example “spring-ex1”
 If your bean configuration file is in file system, then use
following methods to Instantiate container.
 BeanFactory factory = new XmlBeanFactory(new
FileSystemResource("spring.xml"));
Spring Basics
15© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 ApplicationContext context = new
FileSystemXmlApplicationContext("spring.xml");
 If your bean configuration file is in class path, then use
following methods to Instantiate container.
ApplicationContext context = new
ClassPathXmlApplicationContext("spring.xml");
 Subdirectory of class path
ApplicationContext context = new
ClassPathXmlApplicationContext("/beans/spring.xml");
Spring Basics
16© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 Using with Web Applications
Instantiate container with special listener when app
loads. And access container with static methods in
WebApplicationContextUtils.
 Get instance from the container
YourType yourBean =
(YourType) context.getBean("bean-name");
Spring Basics
17© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 How to set BEAN properties ?
 <property name="foo" value="bar"/>
When you declare a bean with above syntax
it calls the zero-argument constructor when the object is
instantiated. Use <property…/> tags to specific what
setters are called after the constructor executes.
<bean id="some-name" class="package.SomeClass">
<property name="someProp" value="some-value"/>
</bean>
Spring Basics
18© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 This means that when getBean() is called, the zero argument
constructor is called, then setXXX is called.
Simple type conversions will be performed, so setXXX can take
String, int, Integer, double, Double, etc.
 <constructor-arg value="…"/>
Instead of calling the zero-arg constructor and then calling setters,
you can supply constructor arguments.
<bean id="some-name" class="package.SomeClass">
<constructor-arg value="some-value"/>
</bean>
Spring Basics
19© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 What to use to initiate objects property or constructor ?
 There may not even be a zero arg constructor in that
case use <property />.
 Use constructor-arg only for immutable classes that
have no setter methods. Use property otherwise.
Spring Basics
20© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
21© 2014 Knowarth
FACTORY METHODS
FACTORY METHODS
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
22© 2014 Knowarth
 <bean factory-method="makeBean">
 Sometimes you don’t know the specific type of bean you will
need. You need to run some logic to determine this.
So, instead of calling constructor, you call a method that returns
an object.
<bean id="some-name" class="package.HelperClass" factory-
method="makeSomeBean">
</bean>
This means that when getBean is called, the static method.
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
23© 2014 Knowarth
 HelperClass.makeSomeBean() is invoked (with no arguments),
and the output of that method is the bean.
Note that “class” is not the class of the bean, but it is a helper
class that contains the static factory method.
 You use the “constructor-arg” to supply values to the factory
method
<bean id="some-name" class="package.HelperClass"
factory-method="makeSomeBean">
<constructor-arg value=“Test"/>
</bean>
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
24© 2014 Knowarth
 This means that the static method call
HelperClass.makeSomeBean(“Test") determines the
output of getBean().
 Note that no constructor is called directly (although
the static method might use a constructor internally).
So “constructor-arg” is a bad choice of name.
 “class” is not the type of the bean, but the name of the
class that contains the static method.
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
25
SCOPE OF BEAN
© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 <bean … scope="singleton"> (or no scope)
Every time you call getBean() on the same name, you
get the same instance. Default if no scope specified.
<property…/> and <constructor-arg…/> only invoked
the first time (if bean of that name not already
instantiated)
 You get the same instance per container. If you
reinstantiate the container, then you get new instance
Why it is required?
26© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
 <bean … scope="prototype">
Every time you call getBean, you get new instance
<property> and <constructor-arg> invoked every time
 Other scopes
scope="request" and scope="session“
Available only in Web applications.
 scope="globalSession"
Used only in portal apps.
27© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
QUERY & QUESTIONS
28© 2014 Knowarth
SLIDE TITLE
 Click to edit Master text styles
 Second level
 Third level
 Fourth level
 Fifth level
THANK YOU
© 2014 Knowarth

More Related Content

What's hot

AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101Rich Helton
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guidePankaj Singh
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview QuestionsSyed Shahul
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAOAnushaNaidu
 
OrchardCMS module development
OrchardCMS module developmentOrchardCMS module development
OrchardCMS module developmentJay Harris
 
Objective-C for Java Developers, Lesson 1
Objective-C for Java Developers, Lesson 1Objective-C for Java Developers, Lesson 1
Objective-C for Java Developers, Lesson 1Raffi Khatchadourian
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 RecipesJosh Juneau
 
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
 
Tumbleweed intro
Tumbleweed introTumbleweed intro
Tumbleweed introRich Helton
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionRichard Paul
 
Project Presentation on Advance Java
Project Presentation on Advance JavaProject Presentation on Advance Java
Project Presentation on Advance JavaVikas Goyal
 
Java j2ee interview_questions
Java j2ee interview_questionsJava j2ee interview_questions
Java j2ee interview_questionsppratik86
 

What's hot (18)

AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
 
Brouchure
BrouchureBrouchure
Brouchure
 
OrchardCMS module development
OrchardCMS module developmentOrchardCMS module development
OrchardCMS module development
 
Azure rev002
Azure rev002Azure rev002
Azure rev002
 
Objective-C for Java Developers, Lesson 1
Objective-C for Java Developers, Lesson 1Objective-C for Java Developers, Lesson 1
Objective-C for Java Developers, Lesson 1
 
Pragmatic orchard
Pragmatic orchardPragmatic orchard
Pragmatic orchard
 
Spring aop
Spring aopSpring aop
Spring aop
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 Recipes
 
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
 
Tumbleweed intro
Tumbleweed introTumbleweed intro
Tumbleweed intro
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency Injection
 
Project Presentation on Advance Java
Project Presentation on Advance JavaProject Presentation on Advance Java
Project Presentation on Advance Java
 
Java j2ee interview_questions
Java j2ee interview_questionsJava j2ee interview_questions
Java j2ee interview_questions
 

Similar to Spring Framework Basics (39

Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scalaMichal Bigos
 
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!
 
Creating master and work repository
Creating master and work repositoryCreating master and work repository
Creating master and work repositoryRavi Kumar Lanke
 
Oop c sharp_part_1
Oop c sharp_part_1Oop c sharp_part_1
Oop c sharp_part_1shivaksn
 
Spring – Java-based Container Configuration
Spring – Java-based Container ConfigurationSpring – Java-based Container Configuration
Spring – Java-based Container ConfigurationDucat India
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2Naga Muruga
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
 
Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015Selena Phillips
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
3.java database connectivity
3.java database connectivity3.java database connectivity
3.java database connectivityweb360
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvcGuo Albert
 
Skillwise-Spring framework 1
Skillwise-Spring framework 1Skillwise-Spring framework 1
Skillwise-Spring framework 1Skillwise Group
 

Similar to Spring Framework Basics (39 (20)

Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
 
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...
 
Hibernate - KNOWARTH
Hibernate - KNOWARTHHibernate - KNOWARTH
Hibernate - KNOWARTH
 
Creating master and work repository
Creating master and work repositoryCreating master and work repository
Creating master and work repository
 
Oop c sharp_part_1
Oop c sharp_part_1Oop c sharp_part_1
Oop c sharp_part_1
 
Spring – Java-based Container Configuration
Spring – Java-based Container ConfigurationSpring – Java-based Container Configuration
Spring – Java-based Container Configuration
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Spring and DWR
Spring and DWRSpring and DWR
Spring and DWR
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Spring boot
Spring bootSpring boot
Spring boot
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015Generic UXD Legos - Selenium Conference 2015
Generic UXD Legos - Selenium Conference 2015
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
3.java database connectivity
3.java database connectivity3.java database connectivity
3.java database connectivity
 
Spring core
Spring coreSpring core
Spring core
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
 
Skillwise-Spring framework 1
Skillwise-Spring framework 1Skillwise-Spring framework 1
Skillwise-Spring framework 1
 

More from KNOWARTH Technologies

More from KNOWARTH Technologies (8)

Introduction to Magento - KNOWARTH
Introduction to Magento - KNOWARTHIntroduction to Magento - KNOWARTH
Introduction to Magento - KNOWARTH
 
Web Framework and Struts 2 - KNOWARTH
Web Framework and Struts 2 - KNOWARTHWeb Framework and Struts 2 - KNOWARTH
Web Framework and Struts 2 - KNOWARTH
 
NodeJS - KNOWARTH
NodeJS - KNOWARTHNodeJS - KNOWARTH
NodeJS - KNOWARTH
 
MongoDB - KNOWARTH
MongoDB - KNOWARTHMongoDB - KNOWARTH
MongoDB - KNOWARTH
 
Java 8 - KNOWARTH
Java 8 - KNOWARTHJava 8 - KNOWARTH
Java 8 - KNOWARTH
 
VMWare based Cloud Computing - KNOWARTH
VMWare based Cloud Computing - KNOWARTHVMWare based Cloud Computing - KNOWARTH
VMWare based Cloud Computing - KNOWARTH
 
Bootstrap - KNOWARTH
Bootstrap - KNOWARTHBootstrap - KNOWARTH
Bootstrap - KNOWARTH
 
Angular JS - KNOWARTH
Angular JS - KNOWARTHAngular JS - KNOWARTH
Angular JS - KNOWARTH
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Spring Framework Basics (39

  • 1. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level By Dinesh Radadiya Spring Basics By Mangalsinh Rajput © 2014 Knowarth
  • 2. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  Introduction  Where we can use spring  Spring Core Module  Types of DI [Dependency Injection]  Factory Methods  Scope of bean Agenda 2© 2014 Knowarth
  • 3. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 3 Introduction © 2014 Knowarth
  • 4. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  Spring provide various level of support for developing enterprise in Java applications. It simplifies many different Java EE tasks.  Spring allows loose coupling between classes so developer can focus on solving the domain problem.  To do this, we require someone who manage these components and it’s dependencies. Introduction 4© 2014 Knowarth
  • 5. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 5© 2014 Knowarth Introduction  This is done by Container which is commonly used in EE, is also used by Spring and is called “IoC” (Inversion of Control) Container. Sequential and Parallel Execution Support.  Spring provides a Container/Factory which manages component instantiation and initialization and component dependencies.
  • 6. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 6© 2013 Knowarth Where we can use spring Spring Basics
  • 7. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 7© 2013 Knowarth Spring Basics Spring framework can be used to develop end to end application DAO Spring DAO Using Spring Support for JDBC ORM Hibernate JPA iBatis JEE JMS EJBs WEB Struts JSF Jasper Report Freemarker Spring MVC AOP Spring AOP AspectJ Integration Core IoC Container
  • 8. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 8© 2013 Knowarth  In typical Java application we can use Spring in following various levels.  Web Layer : Struts 1, Struts2, JSF, Spring MVC  Business Layer : EJBs, Web Services, Spring  Domain Layer : Hibernate, Spring JDBC Templates
  • 9. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 9© 2014 Knowarth  Spring is a lightweight JEE framework designed to provide louse coupling between components and a POJO model.  Spring provides a Container which manages business objects and their lifecycle. Dependencies between various components are supplied via some XML configurations.  Spring Container is factory object in memory making is truly lightweight.
  • 10. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 10 SPRING CORE MODULE © 2014 Knowarth
  • 11. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  Dependency Injection (IoC - Inversion of Control) It is a process in which objects define their dependencies, means , the other objects they work with it. The container then injects those dependencies when it creates the bean. This process is fundamentally the inverse, hence the name Inversion of Control (IoC). This is achieved by XML file that specifies which beans are created and what their properties are. SPRING CORE MODULE 11© 2014 Knowarth
  • 12. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  IoC container is an implementation of BeanFactory interface.  Extension of above interface is ApplicationContext and WebApplicationContext interfaces.  The most commonly used form of IoC container is the ApplicationContext implementation.  Container will get configurations from XML files. SPRING CORE MODULE 12© 2014 Knowarth
  • 13. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 13 TYPES OF DI © 2014 Knowarth
  • 14. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  Setter injection  Constructor injection  Defining a BEAN Objects whose implementations are likely to change are defined in XML file.  Use the <bean> tag to define object’s name and class  Use nested <property> or <constructor-arg> elements to assign values to the object TYPES OF DI 14© 2014 Knowarth
  • 15. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  First create a file called spring.xml and put it in “src” folder of your project.  In that case you can instantiate container with more than one way let’s see it in example “spring-ex1”  If your bean configuration file is in file system, then use following methods to Instantiate container.  BeanFactory factory = new XmlBeanFactory(new FileSystemResource("spring.xml")); Spring Basics 15© 2014 Knowarth
  • 16. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  ApplicationContext context = new FileSystemXmlApplicationContext("spring.xml");  If your bean configuration file is in class path, then use following methods to Instantiate container. ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");  Subdirectory of class path ApplicationContext context = new ClassPathXmlApplicationContext("/beans/spring.xml"); Spring Basics 16© 2014 Knowarth
  • 17. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  Using with Web Applications Instantiate container with special listener when app loads. And access container with static methods in WebApplicationContextUtils.  Get instance from the container YourType yourBean = (YourType) context.getBean("bean-name"); Spring Basics 17© 2014 Knowarth
  • 18. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  How to set BEAN properties ?  <property name="foo" value="bar"/> When you declare a bean with above syntax it calls the zero-argument constructor when the object is instantiated. Use <property…/> tags to specific what setters are called after the constructor executes. <bean id="some-name" class="package.SomeClass"> <property name="someProp" value="some-value"/> </bean> Spring Basics 18© 2014 Knowarth
  • 19. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  This means that when getBean() is called, the zero argument constructor is called, then setXXX is called. Simple type conversions will be performed, so setXXX can take String, int, Integer, double, Double, etc.  <constructor-arg value="…"/> Instead of calling the zero-arg constructor and then calling setters, you can supply constructor arguments. <bean id="some-name" class="package.SomeClass"> <constructor-arg value="some-value"/> </bean> Spring Basics 19© 2014 Knowarth
  • 20. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  What to use to initiate objects property or constructor ?  There may not even be a zero arg constructor in that case use <property />.  Use constructor-arg only for immutable classes that have no setter methods. Use property otherwise. Spring Basics 20© 2014 Knowarth
  • 21. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 21© 2014 Knowarth FACTORY METHODS FACTORY METHODS
  • 22. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 22© 2014 Knowarth  <bean factory-method="makeBean">  Sometimes you don’t know the specific type of bean you will need. You need to run some logic to determine this. So, instead of calling constructor, you call a method that returns an object. <bean id="some-name" class="package.HelperClass" factory- method="makeSomeBean"> </bean> This means that when getBean is called, the static method.
  • 23. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 23© 2014 Knowarth  HelperClass.makeSomeBean() is invoked (with no arguments), and the output of that method is the bean. Note that “class” is not the class of the bean, but it is a helper class that contains the static factory method.  You use the “constructor-arg” to supply values to the factory method <bean id="some-name" class="package.HelperClass" factory-method="makeSomeBean"> <constructor-arg value=“Test"/> </bean>
  • 24. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 24© 2014 Knowarth  This means that the static method call HelperClass.makeSomeBean(“Test") determines the output of getBean().  Note that no constructor is called directly (although the static method might use a constructor internally). So “constructor-arg” is a bad choice of name.  “class” is not the type of the bean, but the name of the class that contains the static method.
  • 25. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level 25 SCOPE OF BEAN © 2014 Knowarth
  • 26. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  <bean … scope="singleton"> (or no scope) Every time you call getBean() on the same name, you get the same instance. Default if no scope specified. <property…/> and <constructor-arg…/> only invoked the first time (if bean of that name not already instantiated)  You get the same instance per container. If you reinstantiate the container, then you get new instance Why it is required? 26© 2014 Knowarth
  • 27. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level  <bean … scope="prototype"> Every time you call getBean, you get new instance <property> and <constructor-arg> invoked every time  Other scopes scope="request" and scope="session“ Available only in Web applications.  scope="globalSession" Used only in portal apps. 27© 2014 Knowarth
  • 28. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level QUERY & QUESTIONS 28© 2014 Knowarth
  • 29. SLIDE TITLE  Click to edit Master text styles  Second level  Third level  Fourth level  Fifth level THANK YOU © 2014 Knowarth

Editor's Notes

  1. Purpose of MVC is separate out each layer so application become easily scalable For example you want to change look of your application only view gets impacted if all 3 layers are properly seperated