I have a simple Spring Bean Expression, which evaluates fine when I define it inside an application context file:
<bean id="myConfigBean" class="com.example.myBeanConfigBean">
<property name="myProperty" value="#{ someOtherBean.getData() }"/>
</bean>
Now, I want to do the same evaluation programmatically. I have used the following code:
final ExpressionParser parser = new SpelExpressionParser();
final TemplateParserContext templateContext = new TemplateParserContext();
Expression expression = parser.parseExpression("#{ someOtherBean.getData() }", templateContext);
final String value = (String) expression.getValue();
This throws an exception:
EL1007E:(pos 22): Field or property 'someOtherBean' cannot be found on null
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?