Spring EL Lists, Maps example

In this article, we show you how to use Spring EL to get value from Map and List. Actually, the way of SpEL works with Map and List is exactly same with Java. See example :

        //get map whete key = 'MapA'
	private String mapA;

	//get first value from list, list is 0-based.
	private String list;

Spring EL in Annotation

Here, created a HashMap and ArrayList, with some initial data for testing.

package com.mkyong.core;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

public class Customer {

	private String mapA;

	private String list;

	public String getMapA() {
		return mapA;

	public void setMapA(String mapA) {
		this.mapA = mapA;

	public String getList() {
		return list;

	public void setList(String list) {
		this.list = list;

	public String toString() {
		return "Customer [mapA=" + mapA + ", list=" + list + "]";


package com.mkyong.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Component;

public class Test {

	private Map<String, String> map;
	private List<String> list;

	public Test() {
		map = new HashMap<String, String>();
		map.put("MapA", "This is A");
		map.put("MapB", "This is B");
		map.put("MapC", "This is C");

		list = new ArrayList<String>();


	public Map<String, String> getMap() {
		return map;

	public void setMap(Map<String, String> map) {
		this.map = map;

	public List<String> getList() {
		return list;

	public void setList(List<String> list) {
		this.list = list;


Run it

       Customer obj = (Customer) context.getBean("customerBean");


Customer [mapA=This is A, list=List0]

Spring EL in XML

See equivalent version in bean definition XML file.

<beans xmlns="http://www.springframework.org/schema/beans"

	<bean id="customerBean" class="com.mkyong.core.Customer">
		<property name="mapA" value="#{testBean.map['MapA']}" />
		<property name="list" value="#{testBean.list[0]}" />

	<bean id="testBean" class="com.mkyong.core.Test" />


Download Source Code

Download It – Spring3-EL-Map-List-Example.zip (6 KB)

About the Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.


1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Andreas Schwarz Recent comment authors
newest oldest most voted
Andreas Schwarz
Andreas Schwarz

//get map whete key = ‘MapA’ -> change ‘whete ‘ to ‘where’