Setter Injection with List

We know that in core java, List is the child interface of Collection. When we want to represent a group of individual objects as a single entity where duplicates are allowed and insertion order is preserved, then we need List. We can create an object of List like

List al=new ArrayList();

Let's see a program for better understanding the concept of Setter Injection with List:

Required Files:


2. spConfig.xml


package java8s;
import java.util.List;
public class WelcomeBean {
    private List employeesData;

    public void setEmployeesData(List employeesData) {
        this.employeesData = employeesData;

    public void show() {


<? xml version = "1.0" encoding = "UTF-8" ?>
    xmlns = ""
    xmlns: xsi = ""
    xmlns: p = ""
    xsi: schemaLocation = "
    http: //">

    <bean id = "id1" class = "java8s.WelcomeBean">
    <property name = "employeesData">
            <value> Arunima Bairiganjan </value> 
            <value> Yogamaya Patra </value> 
            <value> Sutapa Dash </value> 
            <value> Archana Prusti </value> 

package java8s;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;

public class Test {
    public static void main(String[] args) {
        Resource res = new ClassPathResource("spconfig.xml");
        BeanFactory bf = new XmlBeanFactory(res);
        Object ob = bf.getBean("id1");
        WelcomeBean wb = (WelcomeBean) ob;;

About the Author

Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc