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

This class contains three properties with setters and getters and show() method that shows the information. Here, we are using List to display the list of customer names.

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" >
      <list >
        <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;;



Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology, BBSR
Call to: 0674-2361252