Setter Injection with Set

We know that Set is a child interface of Collection. When we want to represent a group of individual object as a single entity where duplicates are not allowed and insertion order is not preserved, then we should go to the collection Set.

Let's see a program for better clarity of Setter Injection with Set.

Required Files:



package java8s;
import java.util.*;
public class Customer {
    private Set customerData;
    public void setCustomerData(Set customerData) {
        this.customerData = customerData;
    public void show() {

<<? xml version = "1.0"
encoding = "UTF-8" ?> 
    xmlns = ""
    xmlns:xsi = ""
    xmlns:p = ""
    xsi:schemaLocation = "">
    <bean id = "id2" class = "java8s.Customer">
        <property name = "customerData">
                <value> Akshay </value> 
                <value> Santosh </value> 
                <value> Tilan </value> 
                <value> Khirod </value> 
                <value> Manu </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 resource = new ClassPathResource("springConfig.xml");
        BeanFactory bf = new XmlBeanFactory(resource);
        Customer c = (Customer) bf.getBean("id2");;

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