web.xml
<bean id="women" class="com.vf.constructor.objectmatch.Women">
<property name="womenService" ref="womenService"></property>
</bean>
<bean id="womenService" class="com.vf.constructor.objectmatch.WomenSerivce">
</bean>
WomenSerivce.java
package com.vf.constructor.objectmatch;
public class WomenSerivce {
/**
* @param args
*/
public WomenSerivce() {
System.out.println("Women service constructor is called.I will take part in HaiTianShengting party.");
}
public void job() {
System.out.println("I will provide fee-based services.");
}
}
Women.java
package com.vf.constructor.objectmatch;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Women {
/**
* @param args
*/
private WomenSerivce womenService;
public void setWomenService(WomenSerivce womenService) {
this.womenService = womenService;
}
public void service() {
womenService.job();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext("web.xml");
Women women = context.getBean("women", Women.class);
women.service();
}
}
output:
Women service constructor is called.I will take part in HaiTianShengting party.
I will provide fee-based services.