ServerWebExchange attributes are empty

蹲街弑〆低调 提交于 2019-12-11 15:16:39

问题


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?


回答1:


It works when firstly I do:

this.handlerMapping.getHandler(serverWebExchange)

where handlerMapping is a bean of type RequestMappingHandlerMapping which you can inject from WebFlux.

This line of code initializes serverWebExchange attributes. In question I wrote that it worked once and then it stopped. The reason for that is that I was experimenting with handlerMapping at that time and it made it work, then I removed it and attributes stopped being initialized. Debugging showed that normally those attributes are set after WebFilters are applied. This line of code makes it initialize earlier.



来源:https://stackoverflow.com/questions/51838281/serverwebexchange-attributes-are-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!