Nella mia app ho alcuni servizi web asincroni. Il server accetta la richiesta, restituisce la risposta OK e avvia la richiesta di elaborazione con AsyncTaskExecutor. La mia domanda è come abilitare richiesta portata qui perché in questo processo ho bisogno di ottenere classe che viene annotata da:Come abilitare lo scope di richiesta nell'esecutore task asincrono
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
Ora ho eccezione:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.requestContextImpl': Scope 'request' 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 thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
perché si corre in SimpleAsyncTaskExecutor
e non in DispatcherServlet
mia elaborazione asincrona di richiesta
taskExecutor.execute(new Runnable() {
@Override
public void run() {
asyncRequest(request);
}
});
dove TaskExecutor è:
<bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
Ha funzionato per me. Devono essere preservati solo i valori di ThreadLocal o MDC. Quindi risolvere il problema. –
Ho appena usato circa la stessa soluzione per SecurtyContext. Questa è una soluzione così bella e pulita per questo problema! Grazie per la condivisione! –
Con Spring 4 (.3.8) questo non sembra funzionare più. L'eccezione è "richiesta Scope" non è attiva per il thread corrente, si consideri la definizione di un proxy con scope per questo bean se si intende fare riferimento ad esso da un singleton, l'eccezione nidificata è java.lang.IllegalStateException: Can not ask for attribute attribute - la richiesta non è più attiva! " –