简体   繁体   中英

How to use @SessionScope beans with Vaadin Broadcaster?

I am using Spring Boot and Vaadin Flow (latest). And I tried the broadcaster example and it works. But as soon as I try to pass the received message to a @SessionScope annotated bean, I am getting an exception

java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request

Any hints on this? Thanks in advance for your time!

Here's what's happening according to my understanding: Spring's @SessionScope beans are created for each HTTP Session, or as the documentation says,

[@SessionScope] Scopes a single bean definition to the lifecycle of a HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.

This means you need to be working in the context of an HTTP session, and as the error message says,

No thread-bound request found: Are you referring to request attributes outside of an actual web request?

The example implementation of the Broadcaster pattern uses a simple background thread executor created by the Executors.newSingleThreadExecutor() - the thread doesn't know anything about HTTP requests or sessions, and it's specifically not running in the context of a web-aware Spring ApplicationContext. .

Your actual problem isn't visible in the question, but hopefully, this answer clarifies the error you're getting and helps you move forward.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM