Home Tutorial Spring Spring3 Ioc Spring Set Factory


Share on Google+Share on Google+
Spring Set Factory
Posted on: August 31, 2010 at 12:00 AM
In this tutorial you will learn about spring set factory and also see the how set is used in spring framework.

Spring Set Factory

Ths SetFactoryBean is a simple factory for shared Set instance. The set element is defined in the xml bean definitions. The setSourceSet method set the source Set which is written in xml list element. The SetTargetSetClass method set the class to use target Set.


package list.factory.example;

import java.util.Set;

public class Week {
	private Set days;

	public List getDays() {
		return days;

	public void setDays(Set days) {
		this.days = days;

	public String toString() {
		return "Days [lists=" + days + "]";



package list.factory.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AppMain {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "context.xml" });
		Week weekday = (Week) context.getBean("week");


<?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:aop="http://www.springframework.org/schema/aop"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

  <bean id="week" class="set.factory.example.Week">
    <property name="days">
      <bean class="org.springframework.beans.factory.config.SetFactoryBean">
        <property name="targetSetClass">
        <property name="sourceSet">


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

Days [lists=[Saturday, Thursday, Monday, Tuesday, Wednesday, Friday, Sunday]]

Download this example code


Related Tags for Spring Set Factory:

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 31, 2010

Recommend the tutorial

Advertisements Advertisements