Easy learning with example program codes

Spring spel list map example

Spring SpEL:

The SpEL stands for Spring Expression Language. It is a powerful expression language which supports querying and manipulating an object graph at the bean creation time or run time. It is similar to other expression languages like JSP EL, OGNL, MVEL and JBoss EL etc with some additional features like method invocation and basic string templating functionality.

Spring SpEL List/Map:

Spring spel provides the facility to get values from List or Map. It works same as in java.


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Component;
public class MapListTest {
	private Map<String, String> map;
	private List<String> list;
	public MapListTest() {
		map = new HashMap<String, String>();
		map.put("stu1", "Mahesh");
		map.put("stu2", "Vivek");
		map.put("stu3", "Bharat");
		list = new ArrayList<String>();
	public Map<String, String> getMap() {
		return map;
	public void setMap(Map<String, String> map) { = map;
	public List<String> getList() {
		return list;
	public void setList(List<String> list) {
		this.list = list;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
public class Student {
	private String stu1;	
	private String list;
	public String getStu1() {
		return stu1;
	public void setStu1(String stu1) {
		this.stu1 = stu1;
	public String getList() {
		return list;
	public void setList(String list) {
		this.list = list;


<beans xmlns=""
 <context:component-scan base-package="" />

import org.springframework.context.ApplicationContext;
 * Spring SPEL Lists, Maps example.
 * @author codesjava
public class Test {
 public static void main(String args[]){	
  //Get application context object.
  ApplicationContext context = 
	new ClassPathXmlApplicationContext("applicationContext.xml");
  //Get studentBean.
  Student student = (Student) context.getBean("studentBean");
  //Print student properties.
  System.out.println("From Map: "+student.getStu1()); 
  System.out.println("From List: "+student.getList()); 


From Map: Mahesh
From List: Nidhi

Download this example.

Copyright © 2018 CodesJava Protection Status SiteMap