我有一個簡單的Spring bean表達,當我把它定義一個應用程序上下文文件中,其評價罰款:編程評估與Spring表達式語言豆表達
<bean id="myConfigBean" class="com.example.myBeanConfigBean">
<property name="myProperty" value="#{ someOtherBean.getData() }"/>
</bean>
現在,我要以編程方式做同樣的評價。我已經使用以下代碼:
final ExpressionParser parser = new SpelExpressionParser();
final TemplateParserContext templateContext = new TemplateParserContext();
Expression expression = parser.parseExpression("#{ someOtherBean.getData() }", templateContext);
final String value = (String) expression.getValue();
這拋出異常:
EL1007E:(pos 22): Field or property 'someOtherBean' cannot be found on null
我想我必須以某種方式設置一個根對象,允許配置的豆等的性質。但我還沒有得到它的工作。任何人,誰已經這樣做,並可以提供一個提示?
我可以使用不帶'@'符號的上述表達式嗎? @ someOtherBean.getData()>> someOtherBean.getData()。 – RiyasAbdulla 2017-04-23 05:11:13
不需要額外的配置;看到編輯我的答案。你真的應該問一個新問題 - 管理員不喜歡評論中的新問題。 – 2017-04-23 14:03:28