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

ODT
Spring IOC advantages and developing spring application sample
PDF
candi-binding-tutorial
ODP
Different Types of Containers in Spring
PPTX
Spring andspringboot training
PDF
9 crucial Java Design Principles you cannot miss
PDF
Ee java lab assignment 4
PDF
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
PPT
Java for Mainframers
Spring IOC advantages and developing spring application sample
candi-binding-tutorial
Different Types of Containers in Spring
Spring andspringboot training
9 crucial Java Design Principles you cannot miss
Ee java lab assignment 4
Spring Web Service, Spring JMS, Eclipse & Maven tutorials
Java for Mainframers

What's hot (18)

PPT
AspMVC4 start101
PDF
Bea weblogic job_interview_preparation_guide
PDF
Hibernate Interview Questions
PPT
Enterprise java beans(ejb) update 2
PPT
Enterprise java beans(ejb)
PPTX
Spring IOC and DAO
DOCX
Brouchure
PDF
OrchardCMS module development
PPTX
Azure rev002
PDF
Objective-C for Java Developers, Lesson 1
PPTX
Pragmatic orchard
PDF
Spring aop
PDF
Java EE 7 Recipes
PPSX
Spring - Part 1 - IoC, Di and Beans
PPT
Tumbleweed intro
PDF
Introduction to Spring's Dependency Injection
PPTX
Project Presentation on Advance Java
PDF
Java j2ee interview_questions
AspMVC4 start101
Bea weblogic job_interview_preparation_guide
Hibernate Interview Questions
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb)
Spring IOC and DAO
Brouchure
OrchardCMS module development
Azure rev002
Objective-C for Java Developers, Lesson 1
Pragmatic orchard
Spring aop
Java EE 7 Recipes
Spring - Part 1 - IoC, Di and Beans
Tumbleweed intro
Introduction to Spring's Dependency Injection
Project Presentation on Advance Java
Java j2ee interview_questions
Ad

Similar to Basics of Spring - KNOWARTH (20)

PDF
Dependency injection in scala
PDF
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
PPTX
Hibernate - KNOWARTH
PDF
Creating master and work repository
PDF
Oop c sharp_part_1
PPTX
Spring – Java-based Container Configuration
PPTX
Creational pattern 2
PDF
Ejb3 Struts Tutorial En
PDF
Ejb3 Struts Tutorial En
PPT
Spring and DWR
PPTX
PPTX
PDF
Entity Framework Core Cookbook 2nd Edition Ricardo Peres
PPT
EJB 3.0 Java Persistence with Oracle TopLink
PPTX
Generic UXD Legos - Selenium Conference 2015
PPTX
Spring framework in depth
PDF
JAVA Object Oriented Programming (OOP)
PPTX
3.java database connectivity
PPTX
Spring core
PDF
Toms introtospring mvc
Dependency injection in scala
Spring Framework Tutorial | Spring Tutorial For Beginners With Examples | Jav...
Hibernate - KNOWARTH
Creating master and work repository
Oop c sharp_part_1
Spring – Java-based Container Configuration
Creational pattern 2
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Spring and DWR
Entity Framework Core Cookbook 2nd Edition Ricardo Peres
EJB 3.0 Java Persistence with Oracle TopLink
Generic UXD Legos - Selenium Conference 2015
Spring framework in depth
JAVA Object Oriented Programming (OOP)
3.java database connectivity
Spring core
Toms introtospring mvc
Ad

More from KNOWARTH Technologies (8)

PPT
Introduction to Magento - KNOWARTH
PDF
Web Framework and Struts 2 - KNOWARTH
PDF
NodeJS - KNOWARTH
PDF
MongoDB - KNOWARTH
PPTX
Java 8 - KNOWARTH
PPTX
VMWare based Cloud Computing - KNOWARTH
PPT
Bootstrap - KNOWARTH
PPTX
Angular JS - KNOWARTH
Introduction to Magento - KNOWARTH
Web Framework and Struts 2 - KNOWARTH
NodeJS - KNOWARTH
MongoDB - KNOWARTH
Java 8 - KNOWARTH
VMWare based Cloud Computing - KNOWARTH
Bootstrap - KNOWARTH
Angular JS - KNOWARTH

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
cuic standard and advanced reporting.pdf
PPTX
Cloud computing and distributed systems.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Big Data Technologies - Introduction.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
KodekX | Application Modernization Development
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Spectroscopy.pptx food analysis technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
Cloud computing and distributed systems.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Big Data Technologies - Introduction.pptx
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
Building Integrated photovoltaic BIPV_UPV.pdf
KodekX | Application Modernization Development
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Encapsulation_ Review paper, used for researhc scholars
Spectroscopy.pptx food analysis technology
Diabetes mellitus diagnosis method based random forest with bat algorithm

Basics of Spring - KNOWARTH

  • 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

  • #5: 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