在SpEL表达式中访问spring bean,同时避免与webflow范围变量发生名称冲突

时间:2014-06-13 16:16:55

标签: java spring spring-webflow spring-el

我在webflow中有以下代码:

<action-state id="blah">
   <evaluate result="flowScope.payPageProxyUrl" expression="payPageProxyUrl"/>

其中表达式中的payPageProxyUrl被定义为spring bean:

<bean id="payPageProxyUrl" class="java.lang.String">
    <constructor-arg value="payPage/Request"/>
</bean>

看来大部分时间通过flow flowScope.payPageProxyUrl正确设置为&#34; payPage / Request&#34;但是在某些情况下(weblogic集群中的其他JVM)我得到以下异常,表明SpEL表达式&#34; payPageProxyUrl&#34;一片空白。我怀疑SpEL并不是一直在访问bean,但你有什么想法,如何在不改变bean / flow范围名称的情况下防止这种情况发生?

这是例外:

org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@21634dc0 targetAction = [EvaluateAction@7e85895f expression = payPageProxyUrl, resultExpression = flowScope.payPageProxyUrl], attributes = map[[empty]]] in state 'blah' of flow 'blah-payment' -- action execution attributes were 'map[[empty]]'
    at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:60) ~[spring-webflow-2.3.1.RELEASE.jar:2.3.1.RELEASE]

...

Caused by: java.lang.NullPointerException: null
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:88) ~[spring-expression-3.2.6.RELEASE.jar:3.2.6.RELEASE]

1 个答案:

答案 0 :(得分:0)

为什么要为String,evaluate,string构造函数等解决spring bean的烦恼;你可以使用set as:

    <action-state id="blah">
        <set name="flowScope.payPageProxyUrl" value="'payPage/Request'"/>
        ...
    </action-state>