spring-projects / spring-webflow

Spring Web Flow
https://spring.io/projects/spring-webflow
Apache License 2.0
325 stars 231 forks source link

Autowired transient properties are not restored after deserialization for beans in flow scope [SWF-1224] #432

Open spring-operator opened 14 years ago

spring-operator commented 14 years ago

Andrey Lipatkin opened SWF-1224 and commented

SWF stores snapshots in serialized format. Snapshot contains beans with @Autowired transient fields in flow scope. When snapshot is restored such fields become null.

There is a working autowiring support for beans defined in \, but beans created outside flow definition are missing this feature.

It seems that there was a special listener in SFW 1.0 (AutowiringFlowExecutionListener) for this reason, but it is missing in SWF 2.0. Here is my temporary solution:

import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.webflow.execution.FlowExecutionListenerAdapter; import org.springframework.webflow.execution.RequestContext;

public class AutowiringFlowExecutionListener extends FlowExecutionListenerAdapter implements BeanFactoryAware { private AutowireCapableBeanFactory beanFactory;

@Override
public void resuming(RequestContext context) {
    for (Object o : context.getFlowScope().asMap().values()) {
        beanFactory.autowireBean(o);
    }
}

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    this.beanFactory = (AutowireCapableBeanFactory) beanFactory;
}

}

Another option would be ability to switch to non-serializing snapshot factory.


Affects: 2.0.8

3 votes, 3 watchers

spring-operator commented 14 years ago

Nicolas Romanetti commented

Hi,

Our team is currently relying on this feature and workaround to declare top level flow variables that carry search critieria (we have one such variable per 'search' flow, and we have dozens of 'search' flow...)

They do not want to declare the variable in the flow itself using the \ tag as it would force them to set the class attribute and it would not survive code refactoring.

Another solution would be may be to set the flow scope to "conversation", as I understand, variables under this scope are not serialized... BTW I don't understand why flow and conversation behave differently in that respect.

Nicolas.