The Spring Framework has bean support for the Collections. It provide list, set, map and props elements. Here in this tutorial you will see about the map elements which is used to set values inside the map.
CollegeBean.java
package collection.map.example;
|
StudentBean.java
package collection.set.example;
|
MapMain.java
|
package collection.map.example; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MapMain { public static void main( String[] args ) { BeanFactory beanfactory = new ClassPathXmlApplicationContext("context.xml"); CollegeBean coll = (CollegeBean)beanfactory.getBean("collegeBean2"); System.out.println(coll); } } |
context.xml
<!-- Spring Map Property --> |
| College [Maps={Key 1=1, Key 2=Student [address=pune, name=suraj], Key 3=Student [address=patna, name=satya]}] |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.