You are on page 1of 33

Lecture 7

Introduction: 1-1
Introduction: 1-2
Introduction: 1-3
Introduction: 1-4
Introduction: 1-5
Introduction: 1-6
Introduction: 1-7
Introduction: 1-8
Introduction: 1-9
class Student class Address
{ {
int roll; String city
String name; String state
Address address; String country

} }

Introduction: 1-10
class Student class Address
{ {
int roll; String city
String name; String state
Address address; String country
}
}
Object
Object
of
of
Student
Address

Introduction: 1-11
Using Setter Injection

Using Constructor Injection

Introduction: 1-12
class Student class Address
{ {
int roll; String city
String name; String state
Address address; String country

setRoll() { } setCity() { }
setName() { } setState() { }
setAddress() { } setCountry() { }
} }

Introduction: 1-13
class Student class Address
{ {
int roll; String city
String name; String state
Address address; String country

Student(roll, name, address) Address(city, state, country)


{ {

} }
} }

Introduction: 1-14
Where we can declare beans and its dependency

Introduction: 1-15
Introduction: 1-16
Property injection using value as
property
<bean class="com.cit.SpringFirst.Student" name="student1">
<property name="id">
<value>101</value>
</property>
</bean>

Introduction: 1-17
Property injection using value as
attribute
<bean class="com.cit.SpringFirst.Student" name="student1">

<property name="name" value="Debarshi" />

<property name="address" value="Kolkata"/>

</bean>

Introduction: 1-18
Property injection using p Schema and
using value as attribute

<bean class="com.cit.SpringFirst.Student" name="student3"


p:id="103" p:name="Hieu" p:address="Hanoi"/>

Introduction: 1-19
How to inject collection types List?
<bean>
<property name=“”>
<list>
<value> 10 </value>
<value> 1024 </value>
<value> 1024 </value>
<null/>
</list>
</property>
</bean>
Introduction: 1-20
How to inject collection types Set?
<bean>
<property name=“”>
<set>
<value> 10 </value>
<value> 1024 </value>
<null/>
</set>
</property>
</bean>
Introduction: 1-21
How to inject collection types Map?
<bean>
<property name=“”>
<map>
<entry key=“Java” value=“3 Months”/>
<entry key=“Python” value=“2 Months”/>
</map>
</property>
</bean>

Introduction: 1-22
How to inject collection types
<bean>
Properties?
<property name=“”>
<props>
<prop key=“name”> Dev </prop>
<prop key=“school”> EIU </prop>
</props>
</property>
</bean>

Introduction: 1-23
How to inject Reference types
<bean>
Properties?
<property name=“”>
<props>
<prop key=“name”> Dev </prop>
<prop key=“school”> EIU </prop>
</props>
</property>
</bean>

Introduction: 1-24
Constructor Injection
<bean class="ConstructorInjection.Person" name="person1">
<constructor-arg value="123" type=“int”/>
<constructor-arg>
<value>Debarshi</value>
</constructor-arg>
<constructor-arg ref="certificate1" />
</bean>

Introduction: 1-25
Introduction: 1-26
Introduction: 1-27
Introduction: 1-28
Implementing Lifecycle methods
Using XML

<bean
class="com.cit.LifeCycle.Pepsi" name="p1"
init-method="init" destroy-method="destroy” >
<property name="price" value="10"/>
</bean>

Introduction: 1-29
Introduction: 1-30
Introduction: 1-31
Introduction: 1-32
Introduction: 1-33

You might also like