Home Tutorial Spring Spring3 Ioc Spring Set Property


Share on Google+Share on Google+
Spring Set Property
Posted on: August 13, 2010 at 12:00 AM
In this tutorial you will learn about the spring set property.

Spring Set Property

The Spring Framework has bean support for the Collections. It provide list, set, map and props elements. Here in this tutorial you will see about the set elements which is used to set values inside the set.


package collection.set.example;

import java.util.Sets;

public class CollegeBean {
  private Set<Object> sets;

  public Sets<Object> getSets() {
    return sets;

  public void setSets(Set<Object> sets) {
    this.sets = sets;

  public String toString() {
    return "College [sets=" + sets + "]";


package collection.set.example;

public class StudentBean {
  private String name;
  private String address;

  public String getName() {
    return name;

  public void setName(String name) {
    this.name = name;

  public String getAddress() {
    return address;

  public void setAddress(String address) {
    this.address = address;

  public String toString() {
    return "Student [address=" + address + ", name=" + name + "]";


package collection.set.example;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ListMain {
  public static void main(String[] args) {
    BeanFactory beanfactory = new ClassPathXmlApplicationContext(
    College coll = (Collegebeanfactory.getBean("collegeBean1");


  <!-- Spring Sets Property Example  -->

  <bean id="studentBean1" class="collection.set.example.StudentBean">
    <property name="name" value="satya" />
    <property name="address" value="Delhi" />

  <bean id="collegeBean1" class="collection.set.example.CollegeBean">

    <property name="sets">
        <ref bean="studentBean1" />
        <bean class="collection.set.example.StudentBean">
          <property name="name" value="ankit" />
          <property name="address" value="delhi" />

  <!-- End -->

When you run this application it will display output as shown below:

College [sets=[1, Student [address=Delhi, name=satya], Student [address=delhi, name=ankit]]]

Download this example code


Related Tags for Spring Set Property:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 13, 2010

Recommend the tutorial

Advertisements Advertisements