首页 > 解决方案 > ServerWebExchange attributes are empty

问题描述

I have Spring Boot annotation based controller built on WebFlux. I implement WebFilter, inside WebFilter I invoked serverWebExchange.getAttributes() and it returned 4 attributes which is fine. But after that it stopped working and now it always returns empty attributes map. I didn't change anything in controller, but even if I did I should still get those attributes. Why it stopped working?

标签: springfilterspring-webflux

解决方案


它在我第一次做的时候起作用:

this.handlerMapping.getHandler(serverWebExchange)

wherehandlerMapping是一个RequestMappingHandlerMapping可以从 WebFlux 注入的 bean。

这行代码初始化serverWebExchange属性。有问题我写道,它工作过一次,然后就停止了。原因是我当时正在试验handlerMapping并且它使它工作,然后我删除它并且属性停止被初始化。调试表明,通常这些属性是在WebFilter应用 s 之后设置的。这行代码使它更早地初始化。


推荐阅读