I have a spring mvc application which make massive use of beans which are defined in a
request scope. Now I have to use a part of this application outside of this scope (in a
qwertz job in the Magnolia CMS). This doesn’t work of course:
Error creating bean with name ‘requestHelper’: Scope ‘request’ is
not active for the current thread
I can’t change the scope of the beans and I can’t change the code. So my only possibility
seems to change the scope of the current thread to a request scope mockup.
I tried something like
XmlWebApplicationContext context = (XmlWebApplicationContext) ApplicationContextProvider.getApplicationContext() ;
MockServletContext mockServletContext = new MockServletContext("/");
context.setServletContext(mockServletContext);
context.refresh();
But this still doesn’t activate the request scope in the current thread. How can I achieve
this?
Request scope can be activated as follows:
Thoguh I think it’s not a good idea to use such a hack in production code.