How to make a state available to all beans in a “session”?

后端 未结 2 626
灰色年华
灰色年华 2021-01-26 12:38

I have the following design. When a client makes a request to the server, the server creates a state that holds all sorts of info. There are various stateless and stateful beans

2条回答
  •  执笔经年
    2021-01-26 13:06

    I can't inject a stateful bean into a stateless bean.

    You can absolutely inject dependencies this way.

    If the stateful bean is @RequestScoped, any call into the stateless bean on that thread that hits a CDI injected contextual reference (iow proxy) will find its way to the right instance of the stateful bean.

    As long as you use CDI, you don't need to trouble yourself with trying to stash things away in your own threadlocals.

提交回复
热议问题