如何从不同的线程使用 ApplicationContext 会话范围 类
How can I use ApplicationContext session scoped classes from a different thread
使用@Async 注释我想在另一个线程中调用一个方法,该线程可以访问 Session 和 Request 范围 classes。
但是,当 ApplicationContext 尝试获取 bean 时,会生成以下异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sessionInfoClass': Scope 'session' is not active for the current thread;
我曾尝试扩展 ApplicationContextAware class 来保存主线程上下文。
我也试过这个问题的建议解决方案 How to enable request scope in async task executor
源码在Github
我已经为你的回购创建了一个拉取请求来解决这个问题。
基本上,我扩展了 this solution 也用于 Runnable
案例。
要验证它,运行 ThreadSampleApplication
class 然后点击 http://localhost:8080/testAsync
使用@Async 注释我想在另一个线程中调用一个方法,该线程可以访问 Session 和 Request 范围 classes。
但是,当 ApplicationContext 尝试获取 bean 时,会生成以下异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sessionInfoClass': Scope 'session' is not active for the current thread;
我曾尝试扩展 ApplicationContextAware class 来保存主线程上下文。
我也试过这个问题的建议解决方案 How to enable request scope in async task executor
源码在Github
我已经为你的回购创建了一个拉取请求来解决这个问题。
基本上,我扩展了 this solution 也用于 Runnable
案例。
要验证它,运行 ThreadSampleApplication
class 然后点击 http://localhost:8080/testAsync