2:10 am - Saturday January 21, 2017

Spring Collection props 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">

	</bean>

	<bean id="student" class="com.candidjava.Student">

		<property name="studentProperties">
			<props>
				<prop key="Name">Kalai</prop>
				<prop key="Course">JAVA</prop>

			</props>
		</property>

	</bean>
</beans>



 

Student.java

package com.candidjava;

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

public class Student {

	private Properties studentProperties = null;

	public void setStudentProperties(Properties studentProperties) {
		this.studentProperties = studentProperties;
	}

	public Properties getStudentProperties() {
		return studentProperties;
	}
}

StudentMain.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 StudentMain {
	public static void main(String a[]) {

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

		Properties studentProperties = student.getStudentProperties();
		Iterator iterator3 = studentProperties.values().iterator();
		System.out.println("Properties example in Spring");
		System.out.println();
		while (iterator3.hasNext()) {
			Object obj = iterator3.next();

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

	}

}

OUTPUT

DOWNLOAD + SOURCE CODE+JAR FILES

Filed in: Z-A Spring Codes

Comments are closed.