Spring - Work - Day1 - Govind: Lists Lists
Spring - Work - Day1 - Govind: Lists Lists
package com; import java.util.Date; import java.util.ArrayList; import java.util.List; public class A { private List<Object> lists; public List<Object> getLists() { return lists; } public void setLists(List<Object> lists) { this.lists = 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) { this.cw = 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() { System.out.println(lists);//setting of values of collection type from xml file // System.out.println("value of a is ...="+ i); // System.out.println("String Value injected is ="+ Name); } } Injection for dependency...
i);
A(String aa) {//constructor Injection for dependency... System.out.println("i m in A + Value of i is .." + aa);
B CLASS
Spring_Work_Day1_Govind
public class B implements InitializingBean, DisposableBean { String msg; public String getMsg() { return msg; } public void cleanUp() { System.out.println("i m in CleanUp method..."); } public void initIt() { System.out.println("i m in Init Method...."); }
public void setMsg(String msg) { this.msg = msg; } int bbb=10; public void m2(){ System.out.println("i m in m2 of B class"); } public B(){ m2(); System.out.println("I m in B class...."); } @Override public void destroy() throws Exception { System.out.println("i m in Destroy of B"); } @Override public void afterPropertiesSet() throws Exception { // TODO Auto-generated method stub System.out.println("i m in after properties set } }
of B");
Spring_Work_Day1_Govind
C CLASS
package com; import org.springframework.stereotype.Component; public class C { public C(){ System.out.println("im i n C class Constructor"); } }
CLIENT CLASS::
package com; import org.omg.CORBA.portable.ApplicationException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Client { public static void main(String[] args) { //A a=new A(); ApplicationContext ctx=new ClassPathXmlApplicationContext("ApplicationContext.xml"); B a=(B)ctx.getBean("b"); //A a1=(A)ctx.getBean("a"); //A a2=(A)ctx.getBean("a"); //C c=(C)ctx.getBean("c"); //C c2=(C)ctx.getBean("c"); //a.m1(); } }
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>