title: Programmatically evaluate a bean expression with Spring Expression Language
body: <p>I have a simple Spring Bean Expression, which evaluates fine when I define it inside an application context file:</p>
  
  <pre><code>&lt;bean id="myConfigBean" class="com.example.myBeanConfigBean"&gt;
      &lt;property name="myProperty" value="#{ someOtherBean.getData() }"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now, I want to do the same evaluation programmatically. I have used the following code:</p>
  
  <pre><code>final ExpressionParser parser = new SpelExpressionParser();
  final TemplateParserContext templateContext = new TemplateParserContext();
  Expression expression = parser.parseExpression("#{ someOtherBean.getData() }", templateContext);
  final String value = (String) expression.getValue();
  </code></pre>
  
  <p>This throws an exception:</p>
  
  <pre><code>EL1007E:(pos 22): Field or property 'someOtherBean' cannot be found on null
  </code></pre>
  
  <p>I guess I have to set a root object somehow that allows to the configured beans like a property. But I did not get it to work yet. Anyone, who has done this already and could give a hint?</p>