Get all updates of Java4s
Follow Us: Email Newsletter

Spring Dependency Injection With List Collection Property

Spring » On Aug 9, 2011 { 4 Comments } By Sivateja

This is same as <set />, right previous session, but few changes are there, let us see the difference between these two <set /> and <list />

  • In the previous example [ Dependency In The Form Of Set Collection Property ] just change to <list /> where ever we have <set />
  • Set doesn’t allows duplicate right.., but List will allows duplicate values too
  • Create List object like,  List l= new ArrayList()
  • Set cannot put values in order, but List will keep the added values in the same order

If you still need the syntax just see


Note: Mates see, in our xml i have been added sun two times, as List will allows the duplicate values, but set doesn’t.  That’s it mates, but Map is not like these two collection and little more important than these two, so we will see in depth regarding this Map in the next session.

Mates am not giving any example here as its same as setter injection ( Hello World program only, see how easy ;) ),  but you can download the example and test at your locals.

Complete Example On Spring Setter Injection With List Collection

files will be used..

  • spconfig.xml

Directory structure:







You Might Also Like

  ♦ About Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


4 Responses to “Spring Dependency Injection With List Collection Property”
  1. Antony says:


    Thanks for the post. Its really easy to understand.

    I have a doubt here. If in case I use list with generic type then how I inject the list through spring configuration.

    Eg: List studentList;

  2. Harikrishna says:

    Good tutorial for spring beginner…Thanks for the post

  3. Hemalatha says:

    Thanks for the tutorial………clear explanations….learnt a lot…once again tanq:)

  4. Rahul says:

    Nice post for list. Move from the list(in your code) .


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.