问题描述
Spring 新的响应式 Web 通量 api 有一个新的 http 会话实现,位于 这里.我想将最新的 spring web session 集成到新的 spring 反应网络流量中.我似乎无法得到它,我尝试将它作为 bean 注入,但它不起作用.我想像往常一样用 HttpSession 注入它
There is a new implementation of http session for spring new reactive web flux api located here.I would like to integrate the latest spring web session in the new spring reactive web flux. I can't seem to get it, I tried injecting it as a bean, but it does not work. I would like to inject it like I usually do with HttpSession
类似的东西
@Autowired
Websession webSession;
推荐答案
由于 Spring WebFlux 是一个响应式 Web 框架,您不能期望 Web Session 作为 bean 注入(即使在请求范围内).在 Servlet 世界中,每个请求/响应都在单个线程中处理,这支持这些方法(即请求"范围).使用 WebFlux,一个给定的请求可以被多个线程处理.
Because Spring WebFlux is a reactive web framework, you can't expect the Web Session to be injected as a bean (even in the request scope). In the Servlet world, each request/response is processed in a single thread, which enables those approaches (i.e. the "request" scope). With WebFlux, a given request can be processed by multiple threads.
与当前请求/响应关联的 WebSession
实例实际上附加到 ServerWebExchange
(参见 getSession).由于反应式编程模型的性质,您很可能会在 Reactor 运算符中访问该会话 - 因此您不能指望将此实例注入应用程序的其他位置.
The WebSession
instance associated with the current request/response is actually attached to the ServerWebExchange
(see getSession). Because of the nature of the reactive programming model, you're very likely to access that session within a Reactor operator - so you can't expect to inject this instance somewhere else in your application.
这篇关于将 spring Websession 与 spring 反应式 Web 通量集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!