Springs
Springs
Springs
Why Spring?
B.L D.A.L
Bean Bean
After Spring:
Presentation Business
Spring Hibernate
Spring Modules:
In spring 1.x, the framework has divided into 7 well defined modules, but
in spring 2.x the framework is divided into 6 modules only.
SPRING MVC
JDBC
Spring Core:
Struts framework highlevel object is createdActionServlet
Spring J2EE module: spring jee module is an extension to core module, where
core module creates container and jee module makes it as framework.
Spring jee module acts real time services like e-mailing, jms, timer, jndi,
remoting, j18n, etc.., to this spring application.
Spring ORM: This module is also to work with Database, spring ORM module
provides an abstraction layer on top of existing ORM tools.
When compared with spring DAO, Spring ORM module has two benefits.
For example:
{ { {
{ { }
} }
} }
In the above example, Traveler Object is depending on Car Object. So, Traveler
class creating an object of Car class inside it.
If directly the object is created in the dependent then there exists tight
coupling.
According to the above example there is a tight coupling between
Traveler and Car object.
If the method in Car class is changed from move() to run() then, in
Traveler class also the changes are required that is in startJournery()
instead of calling move(), we need to call run().
Eg:
class Traveller
{
Car c=new car()
Void starJourney()
{
C.run()
}
}
Class car
Void run()
Eg
Class Traveller
Vehicle v;
This.v=v;
v.move();
}
Interface Vehicle
Void move();
System.out.println(“…………”);
System.out.println(“…………………………..”);
Type of IOC:
Inversion of control means, separating the implementation of an object from
how the object is constructed.
In case of spring framework, the framework will take care about object
creation and ________ the dependent of object required. As a programmer
we are responsible for only implementation of the business logic.
There are two types of IOC a) Dependency lookup b) Dependency Injection.
The servlet will go in to the pool and take the connection, this is called
Dependency lookup mechanism.
Whereas in spring, spring container will provide the object that means giving
the objects automatically this is called Dependency Injection.
Servlet
SOURCE
DATA
DS 3) pool
con con
2) 1)lookup( )
Dependency Key/ds
mechanism
Dependency lookup:
In this type of IOC, when one object is collaborating with another object,
the first object has to get all the dependencies required explicitly by itself.
In dependency lookup, an external person does not provide collaboration
objects automatically to the first object.
In dependency lookup of IOC, the first object is responsible for obtaining its
collaborating objects from the container (or) repository etc.,
Servlet itself goes to individual registry and takes DataSource object from
the registry by performing lookup operation as shown in above diagram.
Eg: In servlet to EJB communication servlet depends on EJB object for calling the
business logic implemented in an EJB. In this communication nobody will
provide EJB object to servlet object automatically.
Servlet itself goes to EJB container and gets the EJB object from it. It
means there is a dependency lookup.
Dependency Injection:
In this type of, when one object is collaborating with another object, some
external person will be provide, the collaborate object to dependent object
automatically.
In this type of IOC, the first object is not responsible to explicit take the
collaborating object required. It means the first object (dependent) does not
perform any lookup operation.
In case of spring framework, the external person who performs dependency
Injection is called Spring IOC container.
EJB3.x technology and spring framework both are supporting dependency
Injection type of IOC.
Class A {
B ab;
This.ab = ab;
}
do.m2();
Class B {
1.Setter Injection
2.Constructor Injection
3.Interface Injection
In spring framework, we use only setter and constructor injections, but not
interface injection.
In struts 2.x, we have interface injection.
Setter Injection:
In this type of dependency Injection, the spring container, uses setter() in the
dependent class for injecting its dependencies (collaboration).
Eg: class A {
B ob;
public void setOb(B ob){
this.ob = ob;
-----
------
Class B {
------
----
----
int k;
this.k = k;
System.out.println(k);
Sprconfig.xml
<bean>
</property>
</bean>
Note: If we pass a value from an xml file, then we can change that value whenever
it is required by without reopening our java code. It means we can directly modify
the value in xml file and we can run the java code by without any recompilation
of code.
Step1:
Step 2:
Syntax:
Step 3:
a. Get the Bean object from the spring container by calling getBean()
b. While calling getBean(), we need to pass the Bean Id as a parameter.
Step 4:
a. GetBean() always returns object. We need to typecast the object into our
spring bean type.
Object o = factory.getBean(“id”);
DemoBean db = (DemoBean)o;
Step 5:
db.display().
Working with a framework software is nothing but working with set of java
files given by that framework.
If we want to use spring framework in a java client application then we
need to set the framework jar files into classpath.
Spring framework is distributed as a combined jar file for all modules and
also individual jar files for each module.
Spring framework is initially released by interface 2.1 and now it is
renamed as springsource.org
Visit www.springsource.org and download spring framework 3.0.5 zip and
then extract it to get the jar files.
The main jar file of spring is called spring.jar and it depends on
commons.logging.jar
Spring.jar file exits e:\spring-framework-3.0.5\dist folder
we can set individual jar files modules also into the classpath. These
modules jar file are available in
e:\ Spring-frameworks-3.0.5\dist\modules folder.
Commons.logging.jar does not come along with spring framework and we
need to get separately.
To work will all the modules of spring framework, we need to set the
following two jar files in the classpath.
1.spring.jar;
2.common-logging.jar
Strutsframework—craig r mcdanahan
Hibernate--- cravin king
Springframework – Rod Johnson
SpringTest1
welcomeBean.java
spconfig.xml
client.java
*.class
//welcome Bean.java
Public class WelcomeBean
{
Private string message;
public void setMessage(String message)
{
this.message = message;
}
}
//springconfig.xml
http://www.springframework.org/dtd/spring-beans-2.0 dtd>
<beans>
<property name=”message”>
</property>
</bean>
</beans>
//client.java
import org.springframework.core.io.*;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.xml.*;
class Client
Main ( )
Step-1
Step-2
Step-3
Object o = factory.getBean(“id”);
WelcomeBean wb = (WelcomeBean)o;
Step-4
wb.show();
1. Javac WelcomBean.java
2. set classpath = c:\spring.jar;c:\commons-logging-1.0.4.jar;%classpath%
3. client java
o/p w to SFW
Points to remember:
Object o = factory.getBean(“id1”);
Object o1 = factory.getBean(“id1”);
Object o2 = factory.getBean(“id1”);
In the above case, only one object of the WelcomeBean class created and it
is given for 3 times.
The return type of getBean() is Object. Because getBean() is creating all
spring bean object. So, it returns the spring Bean object is returns
superclass reference as spring. Client programmer is type caste into
required Bean class type.
What is the difference between beanFactory and other Factory?
Beanfactory and other factory follows design pattern. It means the factory
produces objects. The difference is BeanFactory produces different Bean objects,
other factory always produces same type of objects.
While constructing spring beans (pojo classes), one spring bean class
depends on another spring bean class, for performing some business
operation.
If one bean class is depending on another bean class object, then we call it
as a object dependency.
If one bean class is depending on another bean class object, then in spring
framework, the spring IOC container is responsible for creating and
initiating the dependencies.
In spring configuration file, we have two ways to inform the container about
this object dependency.
a. By using inner beans.
b. By using <required> element.
By using Inner Beans:
Inner bean needs a bean which is added for a property, by without an id in
the xml file.
In case of Inner bean definition with setter injection. We should add
the <bean> elements inside <property> in the xml.
For eg:
<ref> Element:
When dependencies are in the form of objects then to inform the spring IOC
container, in spring-configuration xml file, we need to configure <ref> element.
<ref> element is associated with either local or parent or bean attributes.
When we add <ref> element then we need to pass id of collaborator bean to its
attribute, because the dependency is in the form of object.
Syntax:
<ref local/parent/bean = "id of collaborator bean"/>
= equal to
<ref local = "id of collaborator bean"/>
<ref local = " "/>
or
<ref local = " "/>
= is not equal to
<ref local="id of collaborated bean" parent="id of " bean= " id of collab "/>
local: if local attribute is used with the <ref> element then the spring ioc
container will verify for the collaborator bean within the same container
(factory).
In generally we try to configure all spring beans into a simple spring
configuration file, but it is not mandatory. Because, we can create multiple
spring configuration files also.
Eg:
public class DemoBean
{
private SampleBean sb;
Spconfig.xml
<beans>
<bean id = "id1" class = "DemoBean" >
<property name = "sb">
<ref local = "id2" />
</property>
</bean>
<bean id = "id2" class "SampleBean">
</beans>
In the above xml file, both the dependent bean and collaborator bean are
configured into the same xml file. It means into the same IOC container. So we
can use local attribute with <ref> tag.
By loading this above xml file, we will get the spring IOC container object
called BeanFactory.
The above BeanFactory statement can also be written like the following.
BeanFactory factory = new XmlBeanFactory(res, nutt);
The above xml configuration can also be created like the following:
spconfig.xml
<beans>
<bean id = "id1" class = "DemoBean" >
<property name = "sb">
<ref local = "id2" />
</property>
</bean>
</beans>
------------
-----------
test.xml
<beans>
<bean id = "id2" class "SampleBean">
</beans>
<beans>
<bean id = "id1" class = "DemoBean" >
<property name = "sb">
<ref parent = "id2" />
</property>
</bean>
</beans>
------------
-----------
test.xml
<beans>
<bean id = "id2" class "SampleBean">
</beans>
In the above xml files, ____ bean is available is available in factory2 and
collaborate bean is available .
So <parent> attribute gettable with <ref> element.
In parent and child factories, the names are given like parent and child, but it
is not possible to get parent factory bean object through child factory.
Eg: Ojbect o = factory.getBean(“id2”);
The above statement is wrong because id2 is related factory (parent).
<bean>
If this attribute is used with <ref> element then the spring IOC container first
verifies for the collaborator bean in the same factory. If not available then it
will search in the parent factory.
bean is the combination of both local and parent.
Bean first works like local and otherwise it works like parent.
springconfig.xml
<beans>
<bean id = "id1" class = "DemoBean" >
<property name = "sb">
<ref parent = "id2" />
</property>
</bean>
</beans>
------------
-----------
test.xml
<beans>
<bean id = "id2" class "SampleBean">
</beans>
Parent
Note: 1. While using <ref> element, if the given id is not found then null will be
assigned to the object, but an exception is not thrown.
2. If id is found, but the class is not a soutable for the required type then an
exception will be thrown by spring IOC container. The exception name is
org.spring-framework.beans.unsatisfiedDependencyInjectionException.
The following spring application is to achieve lose coupling b/w objects. B/w
traveler and vehicle.
In this example we are creating spring beans in the form of interface and
implementation class i.e poji/pojo model.
// Journey.java
public interface Journey
{
void startJourney();
}
//Traveller.java
public class Traveller implements Journey
{
private Vehicle v;
public void setV(Vehicle v)
{
this.v = v;
}
public void startJourney()
{
System.out.println("Journey started:");
v.move();
}
};
// Vehicle.java
public interface Vehicle
{
void move();
}
//car.java
public class car implements Vehicle
{
private String fuelType;
private int maxSpeed;
//MotorBike.java
public class MotorBike implements Vehicle
{
private int maxSpeed;
}
};
springconfig.xml
<beans>
<bean id = "id1" class = "Car" >
<property name = "fuelType">
<value>Diesel</value>
</property>
<property name = "maxSpeed" value = "100"/>
</bean>
<bean id = "id2" class "MotorBike">
<property name = "maxSpeed" value = "100"/>
</bean>
</beans>
//springconfig.xml
<beans>
<bean id = "id1" class = "Car" >
<property name = "u">
<ref bean = "id1"/>
</property>
</bean>
</beans>
In the above xml file, only classes are configured but not an interface.
In springframework, interfaces are not allowed to configure into spring config
file, only classes are allowed.
//client.java
import org.springframework.core.io.*;
import org.springframework.beans-factory.*;
import org.springframework.beans-factory.xml.*;
class Client
{
Resource res1 = new ClasspathResource("spconfig.xml");
BeanFactory bf1 = new XmlBeanFactory(res1);
// parent container
Resource res2 = new ClasspathResource("spconfig.xml");
BeanFactory bf2 = new XmlBeanFactory(res2,bf1);
// child container
Object o = bf2.getBean("id3");
//getting a traveller object from container
Journey jo = (Journey)o ;
jo.startJourney();
};
In spconfig.xml, change <ref> from id1 to id2 and if we run the client
application again then we will get the following o/p:
Journey started
Fuel type: petrol
maxSpeed: 80
MotorBike started happy journey.
In the above client application, we can add the following code to get the Car
class object throw child factory.
Object o1 = factory.getBean(“id1”);
Car c = (Car)o1;
c.move( ) ;
If we run the above client application then we will get the following o/p.
Journey started
Fuel type: petrol
Maxspeed: 80
Car started.
Jdbc does not support: i) collections ii) Inheritance
In the client application we can typecast the given bean object into either its
class type or its interface type.
In the above client application we can directly typecast the objects into
Journey interface type using a single statement.
spconfig.xml
<beans>
<bean id="id1" class = "SampleBean">
<property name = "data">
<set>
<value>100</value>
<value>sathya</value>
<value>1025</value>
<ref bean = "id2" />
</set>
</property>
</bean>
<bean id="id2" class = "restBean">
</beans>
List Collection:
If a springBean is depending on a collection of type list them in spring
config file, we need to configure <list>
We can use <value> and <ref> as sub elements of <list>. The difference
between set and list collections are
Set List
1. Set is an unordered 1. List is an ordered collection.
collection.
2. Set doesn’t allow duplicate 2. List allows duplicate values.
values
3. Set doesn’t allow index based 3. List allows index based
accessing. accessing.
4. Set doesn’t support List 4. List supports ListIterator
Iterator.
Eg:
public class SampleBean
{
private List data;
public setData(List data)
{
this.data = data;
}
public void m1()
{
}
};
SPConfig.xml
<beans>
<bean id="id1" class = "SampleBean" >
<property name = "data">
<list>
<value> sathya </value>
<value>100</value>
<value>10.25</value>
<ref bean= "id2" />
<value>100 </value>
</list> </property> </bean>
<bean id="id2" class="TestBean"/>
</beans>
In client application, whenever we call factory.getBean(“id1”) then
internally springcontainer framework executes the following code.
TestBean tb = new TestBean();
List l = new ArrayList();
l.add(“sathya”); l.add(100); l.add(10.25);l.add(tb);l.add(100);
SampleBean ob = new SampleBean();
ob.setData(l);
If a Map collection contains 3 key,value pairs then internally it means 3
objects of MapEntry class.
Map Collection:
In a springbean, if we take collection type as Map then in spconfig file
we should configure the <Map>. In spconfig file, we need to use the sub
element of <Map> as <entry> in a Map collection one entry represents
(key, value)
We use sub element of <entry> as either <value> or <ref>
Eg:
public class SampleBean
{
private Map data;
public setData(Map data)
{
this.data = data;
}
public void m1()
{
}
};
SPConfig.xml
<beans>
<bean id="id1" class = "SampleBean" >
<property name = "data">
<map>
<entry key = "k1">
<value> sathya </value> </entry>
<entry key="10">
<value>100</value> </entry>
<entry key="k2">
<ref bean= "id2" /> </entry>
<value>100 </value>
</map> </property> </bean>
<bean id="id2" class="TestBean"/>
</beans>
Ex2:
The following example has storing by typed Map collection.
public class SampleBean
{
private Map<String, Float> data;
public setData(Map<String, Float> data)
{
this.data = data;
}
public void m1()
{
}
};
<beans>
<bean id="id1" class = "SampleBean" >
<property name = "data">
<map>
<entry key = "k1">
<value> 10.20 </value> </entry>
<entry key="10">
<value>15.20</value> </entry>
<entry key="k2">
<ref bean= "id2" /> </entry>
<value>18.92 </value>
</map> </property> </bean>
<bean id="id2" class="TestBean"/>
</beans>
//inner class
class A
{
class B //inner class
{
----------
----------
};
};
//nested class
class A
{
static class B // nested class
{
------------
------------
};
};
<beans>
<bean id="id1" class = "SampleBean" >
<property name = "data">
<propo>
<prop key = "k1">Durga</prop>
<prop key = "k2">100</prop>
</propo>
</property>
</beans>
The following app is for injecting collection dependencies into a spring bean
E:\ -> Durga -> spconfig.xml
C:\ -> SpringTest3 ->SampleBean.java, client.java, *.class
//SampleBean.java
import java.util.*;
public class SampleBean
{
private Map<String, Integer> Students;
private List data;
}
}
//SPconfig.xml
<bean>
<bean id="id1" class = "SampleBean">
<property name = "Students">
<map>
<entry key = "Ram">
<value> 500 </value> </entry>
<entry key = "java">
<value> 999 </value> </entry>
</map> </property>
<property name = "data">
<list>
<value> Durga </value>
<value> 120 </value>
<value> 30.67 </value>
</list>
</property>
</bean>
</beans>
//Client.java
import org.springframework.core.io.*;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.xml.*;
Constructor injection:
In this type of injection, spring framework or spring Container uses
constructor of the bean class for assigning the dependencies.
In spconfig file, we need to inform the springIOC container about
constructor injection by using <constructor-arg>
In the springbean class, if both constructor and setter injection applied for
the same property then constructor injection will be overridden by setter
injection.
For ex:
public class DemoBean
{
private String message;
<beans>
<bean id="id1" class="DemoBean">
<constructor-arg>...constructor injection
<value>welcome </value>
</constructor-arg>
<property name="message">
<value>hello</value>
</property>
</bean>
</beans>
According to the above xml, DemoBean obj is created with 100 as id and 10 as
sname.
public class DemoBean
{
public String uname,pwd;
public DemoBean(String uname, String pwd)
{
this.uname = uname;
this.pwd = pwd;
}
------------
------------
}
};
<beans>
<bean id="id1" class="DemoBean">
<constructor-arg index="1" value="sathya"/>
<constructor-arg index="0" value="ten" />
</bean>
</beans>
According to the above xml DemoBean object is created with ten as username
and sathya as password.
<beans>
<bean id="id1" class="DemoBean">
<constructor-arg ref = "id2"/>
</bean>
<bean id = "id2" class="sampleBean"/>
</beans>
In the above xml file ref is used as an attribute, it is equal to ref bean. It is not
equal to ref local and ref parent.
Circular Dependency:
Q. what is circular dependency?
Ans: If A and B are two classes and if A depends on B and B depends on A then
we will get circular dependency.
Whenever circular dependency is occurred then we can’t solve this problem
with the help of constructor injection in this case instead of constructor
injection we need to use setter injection.
For ex:
class A
{
B b;
A(B b)
{
this.b = b;
}
};
class B
{
A a;
B(A a)
{
this.a=a;
}
};
<beans>
<bean id="id1" class="A">
<constructor-arg ref = "id2"/>
</bean>
<bean id = "id2" class="B">
<constructor-arg ref = "id1"/>
</bean>
</beans>
//spconfig.xml
<beans>
<bean id="id1" class="A">
<property name="b" ref = "id2"/>
</bean>
<bean id = "id2" class="B">
<constructor-arg ref = "id1"/>
</bean>
</beans>
For eg:
class A
{
private int id;
private String sname;
Spconfig.xml:-
<beans>
<bean id=”id1 class=”ExampleBean1”
Autowrite=”byname”>
</bean>
<bean id=”id2” class=”ExampleBean2”/>
</beans>
2)Bytype:in the case the springfw attempts to bind out the class in xml file
whose name Is matching with the property type to be wired (or) not.
if found then injection that class obj by calling setter injection
if no class found in the xml with the same name then that property remains
unwired.
If a class is found in xml for more than once then springfw throws unsatisfied
dependency injection exception.
Simple:-in this case spring container verifies for primitives and collections are set
(or) not. If not set then exception will be thrown.
Object:-in this case, spring container verifies whether objects are set (or) not, if
not the container throws an exception.
All:-in this case the container verifies for both primitives collections and objects.
//car.java
Public class car
{
Private void setW(wheel w)
[
This.w=w;
}
Public void display()
{
Sop(“done”);
}
}
springTest3
car.java
wheel.java
client.java
*.classes
Spconfig.xml
.wheel.java
Public class wheel
{
---
};
Spconfig.xml
<beans>
<bean id=”id1” class=”car” dependency-check =”objects”/>
<bean id=”id2” class=”wheel”/>
</beans>
//client.java:-
Import org.springframework.context.*;
Import org.springframework.support.*;
Class client
{
Public svm()
ApplicationContext ctx=new classpathXmlApplicationContext(“spconfig.xml”)
Object o=ctx.getBean(id1”);
Car c=(Car)o;
c.display ( );
}
}
In the above client application, we have used the second spring IOC container
called ApplicationContext.
In springfw, we have two IOC container.
1)BeanFactory
2) Applicationcontext
BeanFactory-(i)
Applicationcontext(i)
ClasspathXmlApplicationContext(c) XmlwebApplicationContex(c)
FilesystemXmlApplicationContex(c)
For example:-
Public class TestBean implements InitializingBean, DisposableBean
{
Public Void afterPropertiesSet()
{
//initialization logic
}
Public void destroy()
{
Deinitiaalization (clean-up)logic
}
}
It Is not a pojo class.
In the above bean class, whenever client request is given for getting the bean
object then internally the following steps are executed.
1) Object is created.
2) Properties are injected
3) After PropertiesSet() called.
4) Now obj is given to client application,
Before container is removing (destroying) the object, container first calls destroy ()
and then removes that obj from memory .
In the above example, the drawback is our class is not a POJO class . Because it
is implementing from predefined interface given by the framework.
So we can rewrite the above bean class by adding our own methods for initializing
and cleanup.
While configuring the above into xml, we have to add init-method, destroy-
method attributes for the <bean>
<bean id=”id1” class=”TestBean” init-method=”init”
Destroy-method=”teardown”>
--
</bean>
In this case container will do the following, before giving the object to a client.
1) Object is created
2) Properties are injected.
3) Innit() will be called.
4) Object is given to client.
Whenever container is giving to remove the first it calls teardown() and after that
the object is removed.
Bean instantiation:-
Spring framework instantiates/gets a spring bean object, by using the following
three ways.
1) By calling constructor.
2) By calling static factory method.
3) By calling an instance factory method.
2)By calling static factory method:- by default, spring framework makes each
bean as singleton .But whenever the scope of a bean is changed to prototype then
the bean obj becomes non.singleton
If spring programmer doesn’t want to make a springbean as prototype bean then
the programmer has to explicitly make the bean class as singleton
To make a springbean class as a singleton, the following rules are need to be
followed.
1) Create a private static obj of the class, inside the class
2) Create a private constructor.
3) Crete a public static factory method.
While constructing the above bean class into spring config file we need to inform
to the springIOC container that, call static factory method of the bean class to get
an obj of the bean class.
To inform the springIOC container, we should add an attribute called factory-
method to the <bean>
<bean id=”id1” class=”sampleBean”
*factory-method=”getSampleBean”
…
..
</bean>
Whenever getBean() is called from the client application then the IOC container
will get the bean object by using the following statement internally.
(SampleBean sb=SampleBeangetSampleBean();)
After getting the obj. the IOC container applies all injections and initialization
required and then finally returns that bean obj to the client application.
Note:- if we change scope of the bean from singleton to prototype then, still the
bean is a singleton bean only. It means that bean never out as prototype bean.
In the above xml, for the bean id1 we have removed class attributes and we have
added factory-bean.
In a client applicaton, whenever we call factory.getBean(“id1”),internally the
following staments are executed by the container.
SampleBean2 ob2=new SampleBean();
SampleBean ob1=ob2=getInstance();
Question:-can we assign value for private final variable using setter methods
(or) not.
Not possible.
For final instance variables of the class, initialization must be done through
constructor but not through setter.
Spconfig.xml
<bean id=”id1” class=”DemoBean”>
<constructor-arg value=”100”/>
</bean>
1) Inject dependencies
2)Calls setBeanName()
3)Calls setBeanFactory()
4)Calls
afterpropertiesSet()
5)Calls custom intimated
A Bean object life cycle is a circular process, which means the life cycle starts at
“doesn’t exit” and finally ends at “doesn’t exit” only.
After a bean obj is created, the IOC container initializes the object through the
following verifications.
a) Container verifies whether dependencies are exist (or) not.if exist then it
injects the dependencies.
b) The container verifies whether the bean class is implemented from
BeanNameAware interface (or) not if yes then container calls
SetBeanName(), by passing id of that bean.
c) Container verifies whether bean class is implemented from
BeanFactoryAware interface (or) not . if yes then calls SetBeanFactory
method by passing the current container (this) object.
d) Container verifies whether bean class is implemented initializing bean
interface (or) not . if yes then calls afterPropertiesSet()
e) Container verifies any user defined init() is added (or) not if yes then
container calls that custom init()
f) By completing the above operations, the IOC container returns the
initialized bean object to the client application
g) In the client application service methods(Business method) of the bean are
called.
h) Whenever container is going to shutdown, it removes the bean object. It
means first container verifies whether any user defined destroy methods is
added (or) not. If yes then executes it. Implemented DisPosableBean
interface (or) not . if yes then container calls destroy() and finally makes the
bean obj as destroyed
i) When the bean obj is destroyed then again it goes back to “doesn’t exist”
stats.
Question:- what is the diff b/w the sprigIOC containers BeanFactory and
applicationContext?
BeanFactory doesn’t support real time services added to a bean like mailing
messaging , i18n ….etc But Application context supports the services added to
the springbean.