8:45 pm - Monday June 26, 2017

Spring Collection list Example Program in Eclipse

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Project Structure:

Jar Files:

How to Add Jar Files:

 

 spring-config.xml

 

 

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
	<bean id="stringId" class="java.lang.String">
		<constructor-arg>
			<value>Antony</value>
		</constructor-arg>
	</bean>

	<bean id="emp" class="com.candidjava.Emp">
		<property name="empList">
			<list>
				<value>Deepa</value>
				<value>Kalai</value>
				<value>Mathan</value>
				<ref local="stringId" />
			</list>
		</property>
	</bean>
</beans>


Emp.java

package com.candidjava;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class Emp {
	private List empList = null;

	public void setEmpList(List empList) {
		this.empList = empList;
	}

	public List getEmpList() {
		return empList;
	}

}

EmpMain.java

package com.candidjava;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class EmpMain {
	public static void main(String a[]) {

		BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
				"config\\spring-config.xml"));
		Emp student = (Emp) factory.getBean("emp");

		List studentList = student.getEmpList();
		Iterator iterator = studentList.iterator();
		System.out.println("Employees Names:");
		while (iterator.hasNext()) {
			Object obj = iterator.next();

			System.out.println(obj);
			System.out.println();
		}
	}

}

DOWNLOAD + SOURCE CODE

DOWNLOAD+JarFilesForSpring

Filed in: Z-A Spring Codes

Comments are closed.