首页 > 解决方案 > 是否可以生成请求范围?

问题描述

我在我的应用程序中使用了请求范围的 bean:

@Bean
@RequestScope
public BeanA beanA(){
   return new BeanA();
}

而且,只要我收到网络请求就可以了。问题是我现在还支持其他请求源(例如 Spring 数据 redis 侦听器)但是,当我想用​​我得到的值填充它时

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: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

是否可以创建请求范围?

标签: springspring-boot

解决方案


推荐阅读