I migrated a code to run asynchronously, in a Quartz job.
Now I'm getting this error when I try to use a session scoped view, called when the quartz job finishes:
org.quartz.JobExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.vaadinView': Scope 'session' is not active for the current thread
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.vaadinView'
My bean is:
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public class VaadinView implements View, DisposableBean
I know that the Quartz job runs on another thread, an the session context is lost. So, before calling the job I'm storing the request attributes in the job itself
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
Then, before calling the session scoped bean, I'm restoring the request attributes:
RequestContextHolder.setRequestAttributes(attributes); // workaround
vaadinView.doSomethingOnUI(); // error here
The problem is that now a have the same error, but with another message, telling me that the session is required:
Caused by: java.lang.IllegalArgumentException: Session must not be null
at org.springframework.util.Assert.notNull(Assert.java:134)
at org.springframework.web.util.WebUtils.getSessionMutex(WebUtils.java:403)
at org.springframework.web.context.request.ServletRequestAttributes.getSessionMutex(ServletRequestAttributes.java:253)
at org.springframework.web.context.request.SessionScope.get(SessionScope.java:91)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:346)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192)
My question is: how can I use the quartz job thread to update the UI
Note: I'm using Grails + Vaadin + SpringBoot