On the way learning spring 1
Spring 8 - Setting Beans Properties
1. Add new parameter 'sexId' in Java class "Person" and also add 'setsexId()' method in it
2. Insert 'property' in beans.xml. Source code is:
<bean id="person" class="com.caveofprogramming.spring.test.Person"> <constructor-arg value="777" name="id" type="int"></constructor-arg> <constructor-arg value="Mary" name="name" type="String"></constructor-arg> <property name="taxId" value="123"></property> </bean>
3. Delete the old toString method in Person Java class, then Generate new 'toString()' method
Spring 9 - Dependency Injectrion
1. Add a new Java class 'Adress' in the floder which same with App.java;
2. Add this Java class in 'beans.xml' as a new bean; Then set constructor-arg(same in Spring 8 - Person);
3. Add the corresponding java code in App.class, and run it;
Address address = (Address) context.getBean("address");
System.out.println(address);
4.Add Address object in Person.class, then regenerate the toString() method.
5.In beans.xml, inject property in person bean . Source code is: (Dependency Injectrion)
<bean id="person" class="com.caveofprogramming.spring.test.Person"> <constructor-arg value="777" name="id" type="int"></constructor-arg> <constructor-arg value="Mary" name="name" type="String"></constructor-arg> <property name="taxId" value="123"></property> <property name="address" ref="address"></property> </bean>
---恢复内容结束---