NamedScopeEvaluationContext extends StandardEvaluationContext { public void addContext(String contextName, Object context) { contextScope.put(contextName, context); } NamedScopeEvaluationContext(); void addContext(String contextName, Object context);  }
@Test public void testContextEvaluation() { Integer firstContext = new Integer("5"); Map<String, Object> secondContext = new HashMap<String, Object>(); secondContext.put("class", "math"); secondContext.put("carmen", "sandiego"); Map<String, Object> thirdContext = new HashMap<String, Object>(); thirdContext.put("class", "upper"); thirdContext.put("carmen", "Don't know her."); NamedScopeEvaluationContext context = new NamedScopeEvaluationContext(); context.addContext("first", firstContext); context.addContext("second", secondContext); context.addContext("third", thirdContext); ExpressionParser expressionParser = new SpelExpressionParser(); assertEquals(5, expressionParser.parseExpression("first").getValue(context)); assertEquals(Integer.class, expressionParser.parseExpression("class").getValue(context)); assertEquals("math", expressionParser.parseExpression("second.class").getValue(context)); assertEquals("upper", expressionParser.parseExpression("third.class").getValue(context)); assertEquals("sandiego", expressionParser.parseExpression("carmen").getValue(context)); assertEquals("Don't know her.", expressionParser.parseExpression("third.carmen").getValue(context)); boolean spelExceptionCaught = false; try { System.out.println(expressionParser.parseExpression("first.carmen").getValue(context)); } catch (SpelEvaluationException see) { spelExceptionCaught = true; } finally { assertTrue("\"carmen\" should NOT be readable on first context...", spelExceptionCaught); } }