Hi..Below menstion topic All are geting error. pls find your reference code.let me.. package Setter_Injection; import java.util.Iterator; import java.util.List; public class SI_With_Collection { private int id; private String name; private List<String> answers; //setters and getters public void displayInfo(){ System.out.println(id+" "+name); System.out.println("answers are:"); Iterator<String> itr=answers.iterator(); while(itr.hasNext()){ System.out.println(itr.next()); } } } ......Main.... package Setter_Injection; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; public class SI_With_Collection_Main { public static void main(String[] args) { Resource rc= (Resource) new ClassPathResource("SI_Collection.xml"); BeanFactory factory=new XmlBeanFactory(rc); SI_With_Collection qc=(SI_With_Collection)factory.getBean("qt"); qc.displayInfo(); } } .......................SI_Collection.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"> <!-- Setter_Injection.Answer --> <bean id="qt" class="Setter_Injection.SI_With_Collection_Main"> <property name="id" value="1"></property> <property name="name" value="What is Java?"></property> <property name="answers"> <list> <ref bean="answer1"/> <ref bean="answer2"/> </list> </property> </bean> <bean id="answer1" class="Setter_Injection.Answer"> <property name="id" value="1"></property> <property name="name" value="Java is a programming language"></property> <property name="by" value="Ravi Malik"></property> </bean> <bean id="answer2" class="Setter_Injection.Answer"> <property name="id" value="2"></property> <property name="name" value="Java is a platform"></property> <property name="by" value="Sachin"></property> </bean> </beans> | 0 |