MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

Spring Framework

Spring Projects

Spring Project 1

Dependency on collection using Set example
Previous Home Next

Introduction:In the case of dependency on collection, constructor-arg is the sub element of <bean ......> is used to specify the dependency of a collection i.e to be satisfied the constructor-arg element uses set sub element to specify the dependency of set respectively.

Technology use to run this source code

  1. Spring 2.5
  2. Eclipse
  3. JDK 1.6

Source Code

applicationContext.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-2.5.xsd">
<bean id="ab" class="org.r4r.Student">
<constructor-arg value="101"/>
<constructor-arg value="Mukund"/>
<constructor-arg>
<list>
<value>Core Java</value>
<value>J2EE</value>
<value>Struts</value>
<value>Hibernate</value>
<value>Spring</value>
</list>
</constructor-arg>
</bean>
</beans>

 

Student.java

package org.r4r;
import java.util.*;
public class Student {
int id;
String n;
Set<String> course;
public Student(int id, String n, Set<String> course) {
super();
this.id = id;
this.n = n;
this.course = course;
}
public String toString(){
StringBuffer b=new StringBuffer();
b.append("Name:\t\t").append(n).append("\n").append("Course details:\t\n");
Iterator<String> itr=course.iterator();
while(itr.hasNext()){
b.append(itr.next()).append("\n");
}
return b.toString();
}
}

Test.java

package org.r4r;
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 Test {
public static void main(String ar[]){
Resource r=new ClassPathResource("applicationContext.xml");
BeanFactory f=new XmlBeanFactory(r);
Student a1=(Student)f.getBean("ab");
System.out.println("Student information is,");
System.out.println(a1);
}
}

Output:

 Student information is,
Name: Mukund
Course details:
Core Java
J2EE
Struts
Hibernate
Spring
Previous Home Next