Share on Google+Share on Google+

Spring List Factory

In this tutorial you will learn about spring list factory and how list is used in spring framework.

Spring List Factory

Ths ListFactoryBean is a simple factory for shared List instance. The list element is defined in the xml bean definitions. The setSourceList method set the source List which is written in xml list element. The SetTargetListClass method set the class to use target List.

package list.factory.example;

import java.util.List;

public class Week {
	private List days;

	public List getDays() {
		return days;

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

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


package list.factory.example;

import org.springframework.context.ApplicationContext;

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=""
  xmlns:xsi="" xmlns:aop=""

  <bean id="week" class="list.factory.example.Week">
    <property name="days">
      <bean class="org.springframework.beans.factory.config.ListFactoryBean">
        <property name="targetListClass">
        <property name="sourceList">


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

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

Download this example code



Posted on: August 31, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.