Spring_Work_Day1_Govind
package com; import [Link]; import [Link]; import [Link]; public class A { private List<Object> lists; public List<Object> getLists() { return lists; } public void setLists(List<Object> lists) { [Link] = lists; } int i; String Name; B b;//=new B(); C c;//=new C(); private C cw; public C getCw() { return cw; } public void setCw(C cw) { [Link] = cw; } public C getC() { return c; } public void setC(C c) { this.c = c; } public B getB() { return b; } public void setB(B b) { this.b = b; } public String getName() {
Spring_Work_Day1_Govind
return Name; } public void setName(String name) { Name = name; } public int getI() { return i; } public void setI(int i) {//setter this.i = i; } public } public } public void m1() { [Link](lists);//setting of values of collection type from xml file // [Link]("value of a is ...="+ i); // [Link]("String Value injected is ="+ Name); } } Injection for dependency...
A() { [Link]("i m in A + Value of i is .." +
i);
A(String aa) {//constructor Injection for dependency... [Link]("i m in A + Value of i is .." + aa);
B CLASS
package com; import [Link].*; import [Link]; import [Link];
Spring_Work_Day1_Govind
public class B implements InitializingBean, DisposableBean { String msg; public String getMsg() { return msg; } public void cleanUp() { [Link]("i m in CleanUp method..."); } public void initIt() { [Link]("i m in Init Method...."); }
public void setMsg(String msg) { [Link] = msg; } int bbb=10; public void m2(){ [Link]("i m in m2 of B class"); } public B(){ m2(); [Link]("I m in B class...."); } @Override public void destroy() throws Exception { [Link]("i m in Destroy of B"); } @Override public void afterPropertiesSet() throws Exception { // TODO Auto-generated method stub [Link]("i m in after properties set } }
of B");
Spring_Work_Day1_Govind
C CLASS
package com; import [Link]; public class C { public C(){ [Link]("im i n C class Constructor"); } }
CLIENT CLASS::
package com; import [Link]; import [Link]; import [Link]; public class Client { public static void main(String[] args) { //A a=new A(); ApplicationContext ctx=new ClassPathXmlApplicationContext("[Link]"); B a=(B)[Link]("b"); //A a1=(A)[Link]("a"); //A a2=(A)[Link]("a"); //C c=(C)[Link]("c"); //C c2=(C)[Link]("c"); //a.m1(); } }
XML FILE : [Link]
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "[Link] <beans>
Spring_Work_Day1_Govind
<bean id="b" class="com.B" init-method="initIt" destroymethod="cleanUp"><property name="msg" value="i'm property message" /></bean> <bean id="c" class="com.C" /> <bean id="a" class="com.A" singleton="true" > <constructor-arg value="ssss"></constructor-arg> <property <property <property <property name = "b"> <ref local="b"/> </property> name = "c"> <ref local="c"/> </property> name="i" > <value>34</value> </property> name="name" value="abcd"></property> <property name="cw" ref="cBean" />
<property name="lists"> <list> <value>1</value> <value>2</value> </list> </property> </bean> <bean id="cBean" class="com.C"/> </beans>