Details
-
Type:
Bug
-
Status:
Reopened
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: WebFlow
-
Labels:None
Description
Discovered when investigating GRAILS-5953
Create a flow-scoped service:
class CardService {
static transactional = false
static scope = 'flow'
long sum
void addToSum(long i) {
sum += i
}
}
and a simple Webflow controller that uses it:
class CardController {
def cardService
def index = {
redirect action: 'order'
}
def orderFlow = {
start {
action {
cardService.addToSum(123)
success()
}
on('success').to 'finish'
}
finish {}
}
}
And when you access the controller you'll get the error
Error 500: Error creating bean with name 'CardController': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cardService': Scope 'flow' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No request context bound to this thread; to access flow-scoped beans you must be running in a flow execution request Servlet: grails URI: /webfl/grails/card/index.dispatch Exception Message: No request context bound to this thread; to access flow-scoped beans you must be running in a flow execution request
and the relevant stacktrace is
Caused by: java.lang.IllegalStateException: No request context bound to this thread; to access flow-scoped beans you must be running in a flow execution request
at org.springframework.webflow.scope.AbstractWebFlowScope.getRequiredRequestContext(AbstractWebFlowScope.java:88)
at org.springframework.webflow.scope.FlowScope.getScope(FlowScope.java:27)
at org.springframework.webflow.scope.AbstractWebFlowScope.get(AbstractWebFlowScope.java:39)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)
I can't see how this is ever going to work unless we transparently create scoped proxies for flow scoped services.
In that case, users will only see this exception if they try and call something on the service outside of a flow.