-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIByRef
74 lines (65 loc) · 2.11 KB
/
SIByRef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class Address{
private String addressLine1;
private String city;
private String state;
private String country;
//getter and setter for the variables;
public String toString(){
return addressLine1+" "+city+" "+state+" "+country;
}
}
class Employee{
private int id;
private String name;
private Address address;
public void setId(int id){
this.id = id;
}
public int getId(){
return id;
}
public String setId(String name){
this.name = name;
}
public String getName(){
return name;
}
public Address getAddress();
return address;
public void setAddress(Address address){
this.address = address;
}
public void display(){
System.out.println("Id:"+id+" Name"+name)
System.out.println(address);
}
}
//applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="address1" class="Address">
<property name="addressLine1" value="something"></property>
<property name="city" value="Bangalore"></property>
<property name="state" value="Karnataka"></property>
<property name="Country" value="India"></property>
</bean>
<bean id="EmployeeBean" class="Employee">
<property name="id"><value>20</value></property>
<property name="name"><value>maha</value></property> </bean>
//<property name="city"><value>Bangalore</value></property>
<property name="address" ref="address1"></propety>
</beans>
//Test.java
public class Test{
public static void main(String[] args){
Resource resource = new ClassPathResource("applicationContext.xml");
Factory factory = new BeanFactory(resource);
Employee employee = (Employee)factory.getBean(EmployeeBean);
employee.display();
}
}